packages icon indicating copy to clipboard operation
packages copied to clipboard

Add ShellRoute

Open johnpryan opened this issue 3 years ago • 0 comments

This adds ShellRoute, a new route type that builds an inner Navigator:

  final GoRouter _router = GoRouter(
    navigatorKey: _rootNavigatorKey,
    routes: <RouteBase>[
      /// Application shell
      ShellRoute(
        path: '/',
        defaultRoute: '/a',
        builder: (BuildContext context, GoRouterState state, Widget child) {
          /// Builds a Scaffold with a bottom navigation bar.
          return AppScaffold(child: child);
        },
        routes: <RouteBase>[
          /// The first screen to display in the bottom navigation bar.
          GoRoute(
            path: 'a',
            builder: (BuildContext context, GoRouterState state) {
              return const ScreenA();
            },
            routes: <RouteBase>[
              /// The details screen to display stacked on the inner Navigator.
              GoRoute(
                path: 'details',
                builder: (BuildContext context, GoRouterState state) {
                  return const DetailsScreen(label: 'A');
                },
              ),
            ],
          ),
          /// Displayed when the second item in the the bottom navigation bar is selected.
          GoRoute(
            path: 'b',
            builder: (BuildContext context, GoRouterState state) {
              return const ScreenB();
            },
            routes: <RouteBase>[
              /// Same as "/a/details", but displayed on the root Navigator.
              GoRoute(
                path: 'details',
                // Display on the root Navigator
                navigatorKey: _rootNavigatorKey,
                builder: (BuildContext context, GoRouterState state) {
                  return const DetailsScreen(label: 'B');
                },
              ),
            ],
          ),
        ],
      ),
    ],
  );

nested-nav-go-router 2022-08-12 15_08_39

resolves flutter/flutter#108141 resolves flutter/flutter#99126

johnpryan avatar Aug 12 '22 22:08 johnpryan