getRouteBuilderForPath method Null safety
- String path
Given a path, this finds a matching route builder, or it shows an "Unknown Page" Widget
Implementation
_RoutePathWithBuilder getRouteBuilderForPath(String path) {
_RoutePathWithBuilder? matchingRoute;
// For each route, check all paths it has defined and see if we have a match
widget.routes.forEach((key, value) {
if (_checkPathAgainstRoutes(path, key) && matchingRoute == null) {
matchingRoute = _RoutePathWithBuilder(key.join(","), value);
}
});
// If unable to find route, fallback to unknownPathBuilder or a default 404 page.
if (matchingRoute == null) {
print("WARNING: Unable to find a route for $path");
matchingRoute = _buildUnknownPageWidget();
} else {
//print("RouteMatched, ${matchingRoute?.path}");
}
return matchingRoute!;
}