I wrote the registry system with http library in flutter and its database is mysql
I now want to write it login but I do not know what is the best way
For example, in React, we use Local Storage for storage data
but I do not know what is the best way to store token in the flutter
CodePudding user response:
Before use this add shared_preferences from https://pub.dev/packages/shared_preferences
Try this solution to store your token to local preference.
Save the data in shared-preference
SharedPreferences pref = await SharedPreferences.getInstance();
String token = '54dsfdsfsdfsdf5ad4f5sdafsd25f45';
pref.setString('token', token);
Retrive data from shared-preference
SharedPreferences pref = await SharedPreferences.getInstance();
String token = pref.getString('token')
CodePudding user response:
As mentioned by @Chirag,
shared_preference is a nice dependency to store data like user preferences.
But to store auth token or any other token I would prefer to use flutter_secure_storage so the token is encrypted and secured (it support all platforms)