StatefulShellRoute constructor

StatefulShellRoute({
  1. required List<StatefulShellBranch> branches,
  2. GoRouterRedirect? redirect,
  3. StatefulShellRouteBuilder? builder,
  4. StatefulShellRoutePageBuilder? pageBuilder,
  5. bool notifyRootObserver = true,
  6. required ShellNavigationContainerBuilder navigatorContainerBuilder,
  7. GlobalKey<NavigatorState>? parentNavigatorKey,
  8. Map<String, dynamic>? metadata,
  9. String? restorationScopeId,
  10. GlobalKey<StatefulNavigationShellState>? key,
})

Constructs a StatefulShellRoute from a list of StatefulShellBranches, each representing a separate nested navigation tree (branch).

A separate Navigator will be created for each of the branches, using the navigator key specified in StatefulShellBranch. The Widget implementing the container for the branch Navigators is provided by navigatorContainerBuilder.

Applications that rebuild their routing table using GoRouter.routingConfig should provide and reuse key to preserve the shell's page and branch navigator state.

Implementation

StatefulShellRoute({
  required this.branches,
  super.redirect,
  this.builder,
  this.pageBuilder,
  super.notifyRootObserver,
  required this.navigatorContainerBuilder,
  super.parentNavigatorKey,
  super.metadata,
  this.restorationScopeId,
  GlobalKey<StatefulNavigationShellState>? key,
}) : assert(branches.isNotEmpty),
     assert(
       (pageBuilder != null) || (builder != null),
       'One of builder or pageBuilder must be provided',
     ),
     assert(
       _debugUniqueNavigatorKeys(branches).length == branches.length,
       'Navigator keys must be unique',
     ),
     assert(_debugValidateParentNavigatorKeys(branches)),
     assert(_debugValidateRestorationScopeIds(restorationScopeId, branches)),
     _shellStateKey = key ?? GlobalKey<StatefulNavigationShellState>(),
     super._(routes: _routes(branches));