我尝试将CupertinoTabBar
与命名路线一起使用。我尝试添加一个CupertinoTabScaffold
,并在标签栏中显示标签视图,但当应用将应用推送到不同的路线时,应用抛出错误:
FlutterError(无法在_CupertinoTabViewState中找到路径RouteSettings(“/randomONE”,空)的生成器
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => SomeProvider(),
child: MaterialApp(
title: 'Cool Title',
home: CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(title: Text('First Page'), icon: Icon(Icons.access_alarms)),
BottomNavigationBarItem(title: Text('Second Page'), icon: Icon(Icons.account_balance)),
BottomNavigationBarItem(title: Text('Third Page'), icon: Icon(Icons.accessible)),
],
),
tabBuilder: (context, index) {
CupertinoTabView selectedView;
switch (index) {
case 0:
selectedView = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(child: FirstPage());
});
break;
default:
}
return selectedView;
}),
initialRoute: NamedRoutes.splashScreen,
routes: {
'/first': (BuildContext context) => FirstPage(),
'/second': (BuildContext context) => SecondPage(),
'/randomONE': (BuildContext context) => ThirdPage(),
},
),
);
}
}
2条答案
按热度按时间fafcakar1#
您只需完成切换:
laik7k3q2#
在CupertinoTabBar的CupertinoTabView中使用routes或onGenerateRoutes属性,然后在此处传递您的路线。您的问题将得到解决。