GoRouter constructor Null safety

GoRouter(
  1. {required List<RouteBase> routes,
  2. GoRouterPageBuilder? errorPageBuilder,
  3. GoRouterWidgetBuilder? errorBuilder,
  4. GoRouterRedirect? redirect,
  5. Listenable? refreshListenable,
  6. int redirectLimit = 5,
  7. bool routerNeglect = false,
  8. String? initialLocation,
  9. List<NavigatorObserver>? observers,
  10. bool debugLogDiagnostics = false,
  11. GlobalKey<NavigatorState>? navigatorKey,
  12. String? restorationScopeId}
)

Default constructor to configure a GoRouter with a routes builder and an error page builder.

The routes must not be null and must contain an GoRouter to match /.

Implementation

GoRouter({
  required List<RouteBase> routes,
  // TODO(johnpryan): Change to a route, improve error API
  // See https://github.com/flutter/flutter/issues/108144
  GoRouterPageBuilder? errorPageBuilder,
  GoRouterWidgetBuilder? errorBuilder,
  GoRouterRedirect? redirect,
  Listenable? refreshListenable,
  int redirectLimit = 5,
  bool routerNeglect = false,
  String? initialLocation,
  List<NavigatorObserver>? observers,
  bool debugLogDiagnostics = false,
  GlobalKey<NavigatorState>? navigatorKey,
  String? restorationScopeId,
}) : backButtonDispatcher = RootBackButtonDispatcher() {
  setLogging(enabled: debugLogDiagnostics);
  WidgetsFlutterBinding.ensureInitialized();

  navigatorKey ??= GlobalKey<NavigatorState>();

  _routeConfiguration = RouteConfiguration(
    routes: routes,
    topRedirect: redirect ?? (_, __) => null,
    redirectLimit: redirectLimit,
    navigatorKey: navigatorKey,
  );

  _routeInformationParser = GoRouteInformationParser(
    configuration: _routeConfiguration,
    debugRequireGoRouteInformationProvider: true,
  );

  _routeInformationProvider = GoRouteInformationProvider(
      initialRouteInformation: RouteInformation(
          location: _effectiveInitialLocation(initialLocation)),
      refreshListenable: refreshListenable);

  _routerDelegate = GoRouterDelegate(
    configuration: _routeConfiguration,
    errorPageBuilder: errorPageBuilder,
    errorBuilder: errorBuilder,
    routerNeglect: routerNeglect,
    observers: <NavigatorObserver>[
      ...observers ?? <NavigatorObserver>[],
      this
    ],
    restorationScopeId: restorationScopeId,
    // wrap the returned Navigator to enable GoRouter.of(context).go() et al,
    // allowing the caller to wrap the navigator themselves
    builderWithNav:
        (BuildContext context, GoRouterState state, Navigator nav) =>
            InheritedGoRouter(
      goRouter: this,
      child: nav,
    ),
  );

  assert(() {
    log.info('setting initial location $initialLocation');
    return true;
  }());
}