Playing with Shared Preferences in Flutter🎉

Osama Asif
2 min readFeb 1, 2021

Hi guys, Hope you all are doing fine. Today we will take about the usage of shared preferences in a flutter 😃

What are Shared Preferences?

In simple words shared preferences allow you to store small amounts of primitive data as key/value pairs in a file on the device.

Let’s start 😉

How do we use shared preferences in Flutter?

First, install the shared preference dependency in your project 👌

Step 1: Add dependency

Step 2: Creating a service class for the shared preferences.

Note: This is not necessary but I always prefer to do work in this way. It’s up to you, you can directly call the SF method if you want🙂

Step 2: Storing data in SF 🔒

Step 3: Getting data from SF✊🏼

Step 4: Removing data from SF️‍🔥

How to check the data is present in SF or not?

For this, we have a method called to contain.

Hurray…!!!🥳🥳🥳

Now we know how to use shared preferences✌🏽. Support me by giving clap and follow me if you like it🙏🏽

--

--

Osama Asif

Seasoned software engineer with over 6 years of extensive industry experience specializing in the development of mobile applications.