NomoRouterDelegate constructor

NomoRouterDelegate({
  1. Widget? initial,
  2. required NomoAppRouter appRouter,
  3. List<NavigatorObserver> observers = const [],
  4. Map<Key, List<NavigatorObserver>> nestedObservers = const {},
})

Implementation

NomoRouterDelegate({
  this.initial,
  required this.appRouter,
  this.observers = const [],
  this.nestedObservers = const {},
}) {
  WidgetsBinding.instance.addObserver(this);

  initialRouteInfo = initial != null
      ? PageRouteInfo(
          path: "/",
          page: initial!.runtimeType,
        )
      : null;

  routeInfos = [
    if (initial != null) initialRouteInfo!,
    ...appRouter.routeInfos,
  ];

  final nestedNavRoutes = appRouter.nestedRoutes;

  _nestedNavigatorKeys = {
    for (final nestedRoute in nestedNavRoutes)
      nestedRoute.key:
          nestedRoute.navigatorKey ?? GlobalKey<NavigatorState>(),
  };

  _nestedNavigatorNotifiers = {
    for (final nestedRoute in nestedNavRoutes)
      nestedRoute.key: ValueNotifier([]),
  };

  nestedRoutes = {
    for (final nestedRoute in nestedNavRoutes)
      nestedRoute: nestedRoute.underlying,
  };

  ///
  /// Create the initial stack
  ///
  final home = routeInfos.singleWhereOrNull((route) => route.path == "/") ??
      routeInfos.first;
  final homePage = initial != null
      ? initial!
      : appRouter.getRouteForPath(home.path)().page;
  final navRoute = isNestedRoute(home);
  _stack = [
    if (navRoute != null) ...[
      _getNestedRouterPage(navRoute),
      _nestedPageFromRouteInfo(home, homePage),
    ] else
      _pageFromRouteInfo(home, homePage),
  ];
}