packages
packages copied to clipboard
Add ShellRoute
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');
},
),
],
),
],
),
],
);

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