How I can store some specific data in flutter like tokens or username


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


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 'token')) ?? '';
//or, using nullable var
String? token = await 'token');

Answered By – niaina

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *