vijaycreations
Published in

vijaycreations

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

Dependencies

shared_preferences: ^0.5.12

Implementation

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 👉🏻: https://github.com/vijayinyoutube/sharedpreferences

--

--

--

A list of Flutter Tutorials and app templates

Recommended from Medium

My Review of the Google Cloud Cloud Digital Leader BETA Exam

UPMC celebrates 100th anniv amid pandemic

Dingos: The New Year

PostgreSQL Full Text Search (FTS) and Keycloak, part I

Your Journey to Understand Regular Expressions in a PostgreSQL database

Python Terminal Game

Kubernetes —  the ultimate cloud platform?

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

Flutter Developer

More from Medium

Flutter Web Template — Flutter Web Drawer Widget Example

Floor Package | Notes App Example

Floor Package Image

Flutter Puzzle Hack Updates