flutterdartsession

How can I keep my user's login session open in my flutter application?


in my application flutter after a user logs in, I would like the session to remain open. That is, if a user opens the app, he logs in, if he were to close the application and open it later I would like him to be still logged in and not have to re-enter his credentials. I found this flutter_session library but I didn't understand if it's right for me or just to keep the session active between one page and another


Solution

  • if you are not using firebase there is still various option for this task. here's come local storage SharedPreference or GetStorage to store data (credential ) locally until user is logged in. and whenever user logout we will clear stored data. visit this package https://pub.dev/packages/get_storage when user first time login store credentials like

    GetStorage box = GetStorage();
    
    box.write('email',email.value);
    

    When user logout, clear the data

    box.remove('email');
    

    and further when user launch the app we will check if email key has value in it then redirect to home screen or else Login Screen.

    if(box.read('email')!='' || box.read('email')!=null)
      Get.to(HomeScreen());
    else
      Get.to(LoginScreen());