【发布时间】:2023-03-23 17:57:01
【问题描述】:
我正在处理底部导航栏,但我无法完美地按到上一条路线。
如果我从底部导航栏视图项目中选择两个以上的导航按钮,那么当我按下返回按钮时,它将关闭应用程序。
return Scaffold(
body: (_getBody(index, model)),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.white,
selectedItemColor: Color(0xFFf5851f),
unselectedItemColor: Colors.grey,
type: BottomNavigationBarType.fixed,
currentIndex: index,
// onTap: (value) => setState(() => index = value),
onTap: (value) {
setState(() => index = value);
print(value);
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.restaurant),
title: Text('GMA', style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.call),
title: Text('CALL ON ORDER',
style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.notifications),
title:
Text('NOTIFICATION', style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart),
title: Text('CART', style: Theme.of(context).textTheme.body2)),
//TextStyle(fontSize: 12, fontWeight: FontWeight.w600))),
],
),
Widget _getBody(int index, MainModel model) {
switch (index) {
case 0:
return firstpage(); // Create this function, it should return your first page as a widget
case 1:
return ProductSearch(); // Create this function, it should return your second page as a widget
case 2:
return Account(); // Create this function, it should return your third page as a widget
case 3:
return Cart(); // Create this function, it should return your fourth page as a widget
}
}
【问题讨论】:
-
我没有问你问题
-
按下后退按钮是否要返回上一页?
-
如果我从底部导航栏视图项目中选择购物车页面,我想返回 0 index home page on back press
-
能否分享整个代码
-
我已经分享了
标签: flutter