How to check if the user is logged in, if so show other screen?

后端 未结 3 594
夕颜
夕颜 2021-02-01 06:08

My first screen is a login screen and it needs to check if the user is logged in to open the home screen directly but I get an error using this check.

I\'m doing the che

3条回答
  •  你的背包
    2021-02-01 06:25

    Achieved without Firebase, but by using SharedPreferences

    here is a simple code: Main.dart

    Future main() async {
      WidgetsFlutterBinding.ensureInitialized();
      final SharedPreferences prefs = await SharedPreferences.getInstance();
      var isLoggedIn = (prefs.getBool('isLoggedIn') == null) ? false : prefs.getBool('isLoggedIn');
      runApp(MaterialApp(
        debugShowCheckedModeBanner: false,
        home: isLoggedIn ? anotherPage() : loginPage(),
      ));
    }
    

    using flutter package: shared_preferences

提交回复
热议问题