NomoRouterDelegate constructor
NomoRouterDelegate({
- Widget? initial,
- required NomoAppRouter appRouter,
- List<
NavigatorObserver> observers = const [], - Map<
Key, List< nestedObservers = const {},NavigatorObserver> >
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),
];
}