简体   繁体   English

Flutter go_router 根本不导航?

[英]Flutter go_router simply does not navigate?

I implemented go_router into my app today.我今天在我的应用程序中实现了 go_router。 I don't really have much to say except that it just does not navigate if I call context.go('/main') .我真的没什么好说的,只是如果我调用context.go('/main')它就不会导航。 No error, nothing.没有错误,什么都没有。

This is my GoRouter Object in the MaterialApp Widget in the main.dart file:这是我在 main.dart 文件中的 MaterialApp Widget 中的 GoRouter Object:

GoRouter(
        redirect: (BuildContext context, GoRouterState state) {
          if (isAlreadyLoggedIn == null) return '/loading';
          if (isAlreadyLoggedIn!) {
            return '/main';
          } else {
            return '/';
          }
        },
        routes: [
          GoRoute(
              path: '/',
              builder: (context, state) => const LoginPage(title: 'Login')),
          GoRoute(
              path: '/main',
              builder: (context, state) =>
                  const MainPage(title: 'Dashboard')),
          GoRoute(
            path: '/loading',
            builder: (context, state) => const LoadingPage(),
          )
        ]));

If have an Auth Flow, which checks if the User was already logged In.如果有一个 Auth Flow,它会检查用户是否已经登录。 If yes, the User is redirected to the main Page (works here properly).如果是,用户将被重定向到主页(在此处正常工作)。 If not, the User needs to login.如果没有,用户需要登录。 If succeeded, I want to navigate to main.如果成功,我想导航到 main。 And here nothing happens.这里什么也没有发生。

Thank you!谢谢!

you will need to implement refreshListenable on GoRouter , this field will notify to GoRouter when isAlreadyLoggedIn changed.您将需要在refreshListenable GoRouterisAlreadyLoggedIn更改时,此字段将通知GoRouter You can read more at here你可以在这里阅读更多

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

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