onGenerateRoute method
This extension allows the router to be integrated into Navigator, eg:
onGenerateRoute: routes.onGenerateRoute
Implementation
Route<dynamic> onGenerateRoute(RouteSettings settings) {
/// First, look up the route by its name. This is a case where the route is invoked via pushNamed with the
/// arguments in [settings]
_log.info(
"onGenerateRoute: ${settings.name} with arguments ${settings.arguments}");
AppRoute? appRoute = _routeTree.findRouteByKey(settings.name);
_log.info(" -> ${settings.name} found by key: ${appRoute != null}");
dynamic arguments = settings.arguments;
if (appRoute == null) {
/// The parameters are embedded in the url
_log.info(" -> Attempting to extract url parameters");
var match = _routeTree.matchRoute(settings.name);
_log.info(match == null
? " -> Match not found. Falling back to /notFound"
: " -> ${settings.name} extracted $match");
match ??= AppRouteMatch(notFoundRoute!, const DefaultRouteParams());
appRoute = match.route;
arguments ??= match.parameters;
}
/// Changed from generate to generateAny - figure this context doesn't care
/// about type arguments anyway
final Route<dynamic> Function(String, RouteParams) creator =
this.routeFactory.generateAny(appRoute!, null, null, null);
final route = creator(appRoute.route, appRoute.paramConverter!(arguments));
return route;
}