Issue
I'm new to flutter and I want to know how can I store some specific data in the localstorage of flutter app for example tokens or username
So I made some searches and found some dependencies and other techniques using sqlite but I want to know which are the more convenient way Thank you
Solution
Using flutter_secure_storage is the solution, eg:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
final storage = const FlutterSecureStorage();
//button >> onPressed
void _onLoginButton() async{
//do login logic here
//store datas
await storage.write(key: 'token', value: 'token-value');
await storage.write(key: 'username', value: 'username');
}
//eg: to get the value
String token = (await storage.read(key: 'token')) ?? '';
//or, using nullable var
String? token = await storage.read(key: 'token');
Answered By - niaina
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.