buildShellPage method

Page<Object?> buildShellPage({
  1. required BuildContext context,
  2. required AppContext app,
  3. required RouteNavigator router,
  4. required RouteMatches matches,
  5. required RouteLoadResult? loadResult,
  6. required Object? pageScope,
  7. required List<Page<Object?>> pages,
  8. required PopInvokedWithResultCallback<Object?> onPopInvoked,
  9. required DidRemovePageCallback onDidRemovePage,
})

Builds this route's nested Flutter navigator page.

Implementation

Page<Object?> buildShellPage({
  required BuildContext context,
  required AppContext app,
  required RouteNavigator router,
  required RouteMatches matches,
  required RouteLoadResult? loadResult,
  required Object? pageScope,
  required List<Page<Object?>> pages,
  required PopInvokedWithResultCallback<Object?> onPopInvoked,
  required DidRemovePageCallback onDidRemovePage,
}) {
  final match = matches.match(this);
  if (match == null) {
    throw StateError('Shell route is not part of the active route branch.');
  }
  RouteContext<P, S> routeContext(BuildContext buildContext) =>
      RouteContext<P, S>(
        buildContext: buildContext,
        app: app,
        router: router,
        params: match.params,
        search: match.search,
        location: matches.location,
        matches: matches,
      );
  RoutePageContext<P, S, D> readyContext(BuildContext buildContext) =>
      RoutePageContext<P, S, D>(
        buildContext: buildContext,
        app: app,
        router: router,
        params: match.params,
        search: match.search,
        location: matches.location,
        matches: matches,
        data: loadResult!.data as D,
      );
  final key = ValueKey<_RoutePageIdentity>(
    _RoutePageIdentity(identity, match.params, pageScope),
  );

  Widget child(BuildContext context) {
    if (loadResult == null) {
      return pending?.call(routeContext(context)) ?? const SizedBox.shrink();
    }
    final failure = loadResult.error;
    if (failure != null) {
      final current = routeContext(context);
      if (failure is RouteNotFoundException && notFound != null) {
        return notFound!(current);
      }
      if (error != null) return error!(current, failure);
      return ErrorWidget.withDetails(
        message: failure.toString(),
        error: FlutterError(failure.toString()),
      );
    }
    final navigator = Navigator(
      pages: pages,
      onDidRemovePage: onDidRemovePage,
    );
    return build(readyContext(context), navigator);
  }

  return _WidgetPage(
    key: key,
    name: matches.location.toString(),
    onPopInvoked: onPopInvoked,
    child: Builder(builder: child),
  );
}