BottomNavigationBarItem fixed

 BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: (value){


if more then 3 items,, use this.

转载于:https://www.cnblogs.com/pythonClub/p/10758837.html

用了上述方法还是显示不了,而且还报错了 class TarbarPage extends StatefulWidget { final int index; final int flag; const TarbarPage({Key? key, required this.index, required this.flag}) : super(key: key); @override State<StatefulWidget> createState() => _TarbarPageState(); } class _TarbarPageState extends State { int _currentIndex = 0; //底部导航栏当前索引 final _tabPages = [ const HomePage(), const StudyPage( index: 0, ), const FantasticStoryPage(), const SetUpPage() ]; @override Widget build(BuildContext context) { return Scaffold( body: _tabPages[_currentIndex], bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: (flag) { setState(() { _currentIndex = flag; }); String? thirdPageRoute = ModalRoute.of(context)?.settings.name; print('Third page route: $thirdPageRoute'); }, type: BottomNavigationBarType.fixed, items: const [ BottomNavigationBarItem( icon: Icon(Icons.home), label: ('首页'), ), BottomNavigationBarItem( icon: Icon(Icons.school), label: ('学习'), ), BottomNavigationBarItem( icon: Icon(Icons.local_library), label: ('奇闻'), ), BottomNavigationBarItem( icon: Icon(Icons.settings), label: ('设置'), ), ]), ); } } Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { // Navigator.push( // context, // MaterialPageRoute( // builder: (context) => const StudyPage( // index: 0)), // 传递参数selectedIndex为1 // ); Navigator.push( context, MaterialPageRoute( builder: (context) => const TarbarPage( flag: 1, index: 0)), // 传递参数selectedIndex为1 ); }, child: const Text('狠心退出')), ),
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值