onGenerateRoute static method

Route? onGenerateRoute(
  1. RouteSettings settings
)

Generates a route based on the provided RouteSettings.

Handles matching routes, redirects, authorization checks, and fallbacks. Returns a Route if a matching route is found, or null if a near match exists.

Implementation

static Route<dynamic>? onGenerateRoute(RouteSettings settings) {
  final result = analyzeRoute(settings);
  final state = result.state;
  final match = result.match;
  final isNear = result.isNear;

  if (match == null) {
    if (isNear) return null;
    return _globalDefiner.onUnknownRoute(settings, state);
  }

  return _buildMaterialPageRoute(settings, (ctx) {
    final CurrentRoute currentRoute =
        CurrentRoute(context: ctx, route: match, state: state);
    resolveUnathorizedWidget() =>
        _globalDefiner.unauthorizedBuilder?.call(ctx, currentRoute);
    return RouteLoaderWidget(
      currentRoute: currentRoute,
      loader: _globalDefiner.loaderBuilder?.call(currentRoute),
      guardStream: _resolveRedirection(match, currentRoute),
      authenticationTask: match.isAuthorized?.call(currentRoute).then(
          (bool isAuthorized) =>
              isAuthorized ? null : resolveUnathorizedWidget()),
    );
  }, match.options);
}