onGenerateRoute method

Route? onGenerateRoute(
  1. RouteSettings settings

The route generator callback used when the app is navigated to a named route. Set it on the MaterialApp.onGenerateRoute or WidgetsApp.onGenerateRoute to make use of the paths for route matching.


Route<dynamic>? onGenerateRoute(RouteSettings settings) {
    'route: ${}, args: ${settings.arguments.runtimeType}(${settings.arguments})',

  final _namedNavigationPath = namedPathsMap[];

  if (_namedNavigationPath != null) {
    final _route = _createRoute(_namedNavigationPath, settings);
    _lastGeneratedRoute = _route;
    return _route;

  for (final path in paths) {
    final hasMatch = path.matcher(settings);

    if (hasMatch) {
      return _createRoute(path, settings);

  // If no match was found, we let [WidgetsApp.onUnknownRoute] handle it.
  return null;