Reputation: 241
I am new to Flutter. Is it okay to store data like users credentials (username and password) using Shared Preferences package? What is the disadvantage of using Shared Preferences to hold and pass data between multiple screens in Flutter?
Upvotes: 0
Views: 1383
Reputation: 77334
SharedPreferences should be used to persist data. So you can still read it, after the app was closed and opened again.
If you want to access data in different parts of your application, you should use a state management (see documentation) solution. While you can technically misuse shared preferences for this, it's not the right tool for the job. And as it happens when using the wrong tool for the job, it will come with all sorts of strange side-effects and problems, that using the right tool for the job will not have.
Some state management solutions even come with their own take on how to persist the state.
Upvotes: 0
Reputation: 1332
For storing secure data you can use the flutter_secure_storage package.
go through this article once.
Upvotes: 1
Reputation: 1217
Not answering in the way like "disadvantage of using shared preference". Shared preferences is stored in the data folder which could be read by the user only if the user is using the rooted device which gives access to that directory.
Upvotes: 1
Reputation: 657
You better store data that shows whether the user is authenticated or user login id.
SharedPreferences is mostly used to store small amount (2048 bytes) of data.
I don't think it's an efficient way to store data in shared preference just for accessing from different pages. Consider using a common class or state management tools like provider
Upvotes: 2