Shared preferences are used to store the small amount of data like some int
, double
, bool
or string
value in the local memory. Let me take a simple use case of it for your better understanding.
This is one of the best use cases of shared preferences. Once the user gives the correct id and password then we save a bool
value equal to true
in local memory. Let’s say isUserLoggedIn = true
.
Now you can check the value of isUserLoggedIn
whenever the user starts the app and based on the value you can show the login screen or main dashboard directly.
To demonstrate the use of shared preferences in Flutter we will develop a simple app in which you can increase or decrease the number shown in the text filed with the help of these two buttons.
Once you set the desired value then you can terminate the app and restart it again. You will find the same value in the text field because of shared preferences.
#flutter