【发布时间】:2020-05-12 16:59:19
【问题描述】:
我想实现一个带有命名路由的底部导航栏。似乎视图不断刷新,卡住,当我点击底部导航选项卡时,它们无法使用我的代码。
final _navigatorKey = GlobalKey<NavigatorState>();
int currentIndex = 0;
List<String> _pages = <String>[
Routes.startupViewRoute,
Routes.startupViewRoute,
Routes.startupViewRoute,
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Navigator(
key: _navigatorKey,
initialRoute: Routes.startupViewRoute,
onGenerateRoute: Router().onGenerateRoute,
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: currentIndex,
onTap: (index) {
_navigatorKey.currentState.pushNamed(_pages[index]);
},
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text('Home'),
),
BottomNavigationBarItem(
icon: new Icon(Icons.person),
title: new Text('Profile'),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
title: Text('Settings'),
)
],
),
);
【问题讨论】: