admin管理员组

文章数量:1395730

I implemented GoRouter in my application. However, there are 2 issues aries.

  1. The backstack seems broken, because when i back from 3rd screen it pops to Home
  2. Bottom navigation was not hidden in the 2nd and 3rd screen.

Please check the video below.

Here is my GoRouter implementation:

StatefulShellRoute.indexedStack(
  builder: (context, state, child) {
    return BlocProvider(
      create: (context) => HomeBloc()..add(GetHomeMenus()),
      child: HomePage(
        showSuccessSnackbar: false,
        child: child,
      ),
    );
  },
  branches: [
    StatefulShellBranch(
      routes: [
        GoRoute(
          name: RouterList.home, // 1st route
          path: RouterList.home,
          pageBuilder: (context, state) {
            return _getDefaultTransition(state.pageKey, DashboardPage());
          },
          routes: [
            GoRoute( // 2nd route
              name: RouterList.psychotestSim,
              path: RouterList.psychotestSim,
              builder: (context, state) {
                return BlocProvider(
                  create: (context) => SimBloc(),
                  child: SimRegistration(
                    key: UniqueKey(),
                  ),
                );
              },
            ),
            GoRoute( // 3rd route
              // parentNavigatorKey: _rootNavigatorKey,
              name: RouterList.psychotestSimCamera,
              path: RouterList.psychotestSimCamera,
              builder: (context, state) => Placeholder(
                key: UniqueKey(),
              ),
            )
          ],
        )
      ],
    ),
    StatefulShellBranch(
      routes: [
        GoRoute(
          name: RouterList.profile,
          path: RouterList.profile,
          pageBuilder: (context, state) {
            return _getDefaultTransition(state.pageKey, ProfilePage());
          },
        )
      ],
    ),
    StatefulShellBranch(
      routes: [
        GoRoute(
          name: RouterList.result,
          path: RouterList.result,
          pageBuilder: (context, state) {
            return _getDefaultTransition(state.pageKey, Container());
          },
        ),
      ],
    ),
  ],
)

And I navigate to 2nd & 3rd route using context.goNamed(...)

本文标签: flutterGoRouter Shell Route Nested NavigationStack Overflow