What is the benefit or use case of onGenerateRoute
and routes in Flutter.
In my application in first page inside MaterialApp
we can define rout
My solution is to re-assign the settings of MaterialPageRoute.
eg: //配置路由
final routes = {
'/': (context) => MainPage(),
};
// 统一处理
var onGenerateRoute = (RouteSettings settings) {
final String name = settings.name;
final Function pageContentBuilder = routes[name];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
settings: settings,
builder: (context) => pageContentBuilder(context, arguments: settings.arguments));
return route;
} else {
final Route route =
MaterialPageRoute(settings: settings,
builder: (context) => pageContentBuilder(context));
return route;
}
}
};