繁体   English   中英

当我打开我的 flutter 应用程序时,它总是显示登录屏幕几秒钟,即使我已经在上次会话中登录。 在那个主页之后?

[英]When I open my flutter app it always shows Sign In screen for few seconds, even if I already signed In in my last session. And after that Main page?

final _navigatorKey = GlobalKey<NavigatorState>();

class MainApp extends StatefulWidget {
  const MainApp({Key? key}) : super(key: key);

  @override
  _MainAppState createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {

  @override

  Widget build(BuildContext context) {

    return GetMaterialApp(

        localizationsDelegates: context.localizationDelegates,

        supportedLocales: context.supportedLocales,

        locale: context.locale,

        navigatorKey: _navigatorKey,

        color: Colors.white,

        getPages: router.routes,

        initialRoute: SignInPageRoute,

        routingCallback: (routing) {

          final _navigationService = locator<NavigationService>();

          final _authService = locator<AuthService>();

          if (routing!.current == SignInPageRoute) {

            WidgetsBinding.instance!.addPostFrameCallback(
              (_) {
                bool isLoggedIn = _authService.isLoggedIn();
                if (isLoggedIn) {
                  _navigationService.offAllTo(MainPageRoute);
                } else {
                  return;
                }
              },
            );
          }
        });
  }
}

试试这个

bool isLoggedIn = await _authService.isLoggedIn();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM