Published in


Shared Preferences in Flutter

Store the data locally in Flutter app using Shared Preferences.

Shared Preferences is a kind of local storage that we can make use of to store smaller data inside Flutter App. The data in Shared Preferences are stored in the form of key value pair.

Video Tutorial


shared_preferences: ^0.5.12


In this article we shall discuss how to store, retrieve and delete the data using Shared Preferences.

  1. Storing data:

Let me store a String datatype locally using the shared preferences concept.

call the above defined function by passing the data <String> that we want to store locally saveMyName(“myName”) Use setString() to store the data. The setString() accepts the key and the Value . In the above code snippet the name enclosed within codes "name" is the key and the second parameter name is the value.

2. Retrieve data:

Now let’s retrieve the data back what we have stored before.

For Retrieving the data we need to just pass in the key alone. In our case the Key is name . So we have to pass that to get the data back [Line no:4] from Shared Preferences. “Name not found[Line no:4] is a custom message that we show in case if there is no entry for that particular key in the local storage.

3. Deleting the data:

For deleting the particular entry, make use of remove method and pass the key alone as the parameter.

Just like String we can also store Integer and Bool datatypes in Shared Preferences.

For Integer use., getInteger() setInteger()

For Boolean use., getBool() setBool()

👨‍💻Get the complete Source Code here 👉🏻:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vijay R

Vijay R


Hai👋 I’m a flutter developer experienced in designing and developing stunning mobile apps. Reach out for freelance projects: