generateRoute method

Route generateRoute(
  1. RouteSettings routeSettings
)

Generates a route based on the given RouteSettings.

If a matching route is found in the routes map, it returns a MaterialPageRoute with the corresponding widget. Otherwise, it returns a MaterialPageRoute with the initialRoute.

Implementation

Route<dynamic> generateRoute(RouteSettings routeSettings) {
  print('routeSettings.name: ${routeSettings.toString()}');

  final routeBuilder = _findRouteBuilder(routeSettings.name!, routes);

  if (routeBuilder != null) {
    print('routeBuilder: ${(routeBuilder)}');
    return MaterialPageRoute<dynamic>(
      settings: routeSettings,
      builder: (context) => routeBuilder(
        context,
        routeSettings.arguments as Map<String, dynamic>? ?? {},
      ),
    );
  } else {
    // Default route
    return MaterialPageRoute<dynamic>(
      settings: routeSettings,
      builder: (context) => initialRoute,
    );
  }
}