我正在尝试在 CupertinoApp 中添加带有底部导航栏的路由器,但Navigator.pushNamed(context,anotherPage)
出现错误
在 _CupertinoTabViewState 中找不到路由 RouteSettings("/anotherPage", null) 的生成器。
但 Navigator.push(context, CupertinoPageRoute(builder: (context)=>AnotherPage()));
正在工作示例代码:
return CupertinoApp(
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
theme: CupertinoThemeData(brightness: Brightness.light),
onGenerateRoute: Router.generateRoute,
initialRoute: splashScreen,
); }}
//路由器类
class Router {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case homeRoute:
return CupertinoPageRoute(builder: (_) => CupertinoHomePage());
case productDetails:
final ProductDetails args = settings.arguments;
return CupertinoPageRoute(
builder: (_) =>
ProductDetails(args.productsPojo, args.userId));
case anotherPage:
return MaterialPageRoute(builder: (_) => AnotherPage());
case splashScreen:
return MaterialPageRoute(builder: (_) => SplashScreen());
default:
return MaterialPageRoute(builder: (_) => UndefinedView(name: settings.name));
}
}
}