0

I am working on a web app in which, I want to keep user logged in during page refresh or even if the tab is no longer exist just like youtube/gmail web app. How to create that ???

In flutter mobile for android/ios we can used shared preferences which uses shared preferences for android and NSUserDefaults for ios to make that functionality. But in the case of Flutter web we can't store user creds into local/ session storage or even in cookies.

I recently started using flutter web so, please guide me on the right path, any link to good resources is much appreciated.

Atul Chaudhary
  • 1,491
  • 2
  • 15
  • 23
  • You, can use share preference. when you login. then set value when logout then reset value/ change value, https://stackoverflow.com/questions/54377188/how-to-use-shared-preferences-to-keep-user-logged-in-flutter –  Apr 16 '21 at 05:43
  • Don't store user creds into local/ session storage. Store user access token to SharedPreferences. – ישו אוהב אותך Apr 16 '21 at 06:16
  • i have been tried to store the token to shareddPreferences but this didn't worked. when i refreshes my webapp the user gets logged out. – Aqeel Mughal Oct 26 '22 at 10:26

1 Answers1

0

Edited: You can use hivedb packages from pub.dev for safe and high speed storage supporting on web also:

import 'package:hive/hive.dart';
import 'dart:convert';

void main() async {
  //Hive.init('somePath') -> not needed in browser

 var box = await Hive.openBox('testBox');

 box.put('user', json.encode(User(name:'john',password:'pass')));

 print('Name: ${box.get('user')}');
}
  1. https://pub.dev/packages/hive
  2. https://docs.hivedb.dev/#/
Ayyaz meo
  • 450
  • 5
  • 13