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.
In this article we shall discuss how to
delete the data using Shared Preferences.
- 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
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.
String we can also store
Bool datatypes in Shared Preferences.
For Integer use.,
For Boolean use.,
👨💻Get the complete Source Code here 👉🏻: https://github.com/vijayinyoutube/sharedpreferences
Other articles you may like.,
🔵Setting up your Flutter app for publishing in Play Store.
🔴Confetti Animation in Flutter
🟡 Change App Launcher Icon in Flutter
🔴 AnimatedContainer Widget in Flutter
If you want to know more about Flutter and various Widgets in Flutter…?🤓 Then visit my channel vijaycreations🚩