带有flutter go路由器的导航组件

发布于 2025-01-29 12:12:54 字数 1221 浏览 0 评论 0原文

我有这个布局。

我的Go路由器代码:

final appRouter = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
        path: '/',
        builder: (context, state) => HomePage(key: state.pageKey),
        routes: [
          GoRoute(
            path: 'dashboard',
            builder: (context, state) => DashboardPage(),
          ),
          GoRoute(
            path: 'audit',
            builder: (context, state) => const AuditPage(),
          ),
        ]),
  ],
  errorPageBuilder: (context, state) => MaterialPage(
    key: state.pageKey,
    child: Scaffold(
      body: Center(
        child: Text(state.error.toString()),
      ),
    ),
  ),
);

如果我想要正常的导航,我该怎么办。 因此,当我选择每个菜单时,它将用屏幕代替绿色面板。使用状态可能很容易。但是可以与Go Router一起使用。我看到嵌套导航文档。它令人困惑。

Autoroute软件包中提供了类似的东西。

“在此处输入图像说明”

I have this layout.

[1]: https://i.sstatic.net/vHL4y.png

my go router code:

final appRouter = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
        path: '/',
        builder: (context, state) => HomePage(key: state.pageKey),
        routes: [
          GoRoute(
            path: 'dashboard',
            builder: (context, state) => DashboardPage(),
          ),
          GoRoute(
            path: 'audit',
            builder: (context, state) => const AuditPage(),
          ),
        ]),
  ],
  errorPageBuilder: (context, state) => MaterialPage(
    key: state.pageKey,
    child: Scaffold(
      body: Center(
        child: Text(state.error.toString()),
      ),
    ),
  ),
);

How can I do if I want normal navigation just like bottom navigation or tab navitation.
So, when I select each menu, it replaces the green panel with the screen. It may be simple to use state with condition. but it is possible to use with go router. I see nested navigation documentation. Its abit confusing.

There is something like this provided in AutoRoute package.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路黄昏 2025-02-05 12:12:54
StatefulShellRoute.indexedStack(
    builder: (context, state, navigationShell) {
      return BottomNavBarCustom(shell: navigationShell);
    },
    branches: [
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.homeView.path,
          builder: (context, state) => const HomeView(),
        ),
      ]),
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.settingsView.path,
          builder: (context, state) => const ProfileView(),
        ),
      ]),
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.financeView.path,
          builder: (context, state) => const FinanceView(),
        ),
      ]),
    ],
  ),
**you can use it like this. It will provide you with an index**
StatefulShellRoute.indexedStack(
    builder: (context, state, navigationShell) {
      return BottomNavBarCustom(shell: navigationShell);
    },
    branches: [
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.homeView.path,
          builder: (context, state) => const HomeView(),
        ),
      ]),
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.settingsView.path,
          builder: (context, state) => const ProfileView(),
        ),
      ]),
      StatefulShellBranch(routes: [
        GoRoute(
          path: AppRouterName.financeView.path,
          builder: (context, state) => const FinanceView(),
        ),
      ]),
    ],
  ),
**you can use it like this. It will provide you with an index**
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文