flutter之底部导航栏制作

  1. 在lib目录下新建pages文件夹,并新建dart文件,效果如图所示

 

 

2.在main.dart文件中写代码,效果如图所示

 

3.在index_page.dart文件中写代码,效果如图所示

 

 

4.在home_page.dart文件中写代码,效果如图所示

 

5.在cateory_page.dart文件中写代码,效果如图所示

 

6.在cart_page.dart文件中写代码,效果如图所示

 

7.在member_page.dart文件中写代码,效果如图所示

 

效果如图所示:

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter 底部导航栏可以使用 `BottomNavigationBar` 组件来实现。 首先,需要在 `StatefulWidget` 的 `build` 方法中创建 `BottomNavigationBar` 组件并设置它的 `items` 属性,该属性接受一个包含每个导航项的 `BottomNavigationBarItem` 对象的列表。 例如: ```dart class MyBottomNavigationBar extends StatefulWidget { @override _MyBottomNavigationBarState createState() => _MyBottomNavigationBarState(); } class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> { int _currentIndex = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('My Bottom Navigation Bar'), ), body: Container( child: Center( child: Text('This is the $_currentIndex tab'), ), ), bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: (int index) { setState(() { _currentIndex = index; }); }, items: [ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', ), BottomNavigationBarItem( icon: Icon(Icons.search), label: 'Search', ), BottomNavigationBarItem( icon: Icon(Icons.person), label: 'Profile', ), ], ), ); } } ``` 在这个例子中,我们创建了一个 `_currentIndex` 变量来存储当前选中的导航项的索引。在 `build` 方法中,我们创建了一个包含三个导航项的 `BottomNavigationBar` 组件,并将其传递给 `bottomNavigationBar` 属性。每个导航项都由一个 `BottomNavigationBarItem` 对象表示,它包含一个图标和一个标签。 我们还为 `BottomNavigationBar` 组件设置了 `currentIndex` 属性,以确定当前选中的导航项。当用户点击某个导航项时,我们使用 `onTap` 回调函数来更新 `_currentIndex` 变量,并调用 `setState` 方法来重建界面。 最后,我们将 `BottomNavigationBar` 组件放在 `Scaffold` 组件的 `bottomNavigationBar` 属性中,并将其他内容放在 `Scaffold` 组件的 `body` 属性中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值