更多文章请查看 lutter从入门 到精通

实现底部导航栏并点击切换页面可简述为有三种方式

  • TabBar + TabBarView
  • BottomNavigationBar + BottomNavigationBarItem
  • 自定义 BottomAppBar

在这里 使用 BottomAppBar 来实现


/*** 有状态StatefulWidget*  继承于 StatefulWidget,通过 State 的 build 方法去构建控件*/
class BotomeMenumBarPage extends StatefulWidget {通过构造方法传值BotomeMenumBarPage();//主要是负责创建state@overrideBotomeMenumBarPageState createState() => BotomeMenumBarPageState();
}/*** 在 State 中,可以动态改变数据* 在 setState 之后,改变的数据会触发 Widget 重新构建刷新*/
class BotomeMenumBarPageState extends State<BotomeMenumBarPage> {BotomeMenumBarPageState();@overridevoid initState() {///初始化,这个函数在生命周期中只调用一次super.initState();}@overrideWidget build(BuildContext context) {//构建页面return buildBottomTabScaffold();}//当前显示页面的int currentIndex = 0;//点击导航项是要显示的页面final pages = [ChildItemView("首页"),ChildItemView("发现"),ChildItemView("动态"),ChildItemView("我的")];Widget buildBottomTabScaffold() {return SizedBox(height: 100,child: Scaffold(//对应的页面body: pages[currentIndex],//appBar: AppBar(title: const Text('Bottom App Bar')),//悬浮按钮的位置floatingActionButtonLocation:FloatingActionButtonLocation.centerDocked,//悬浮按钮floatingActionButton: FloatingActionButton(child: const Icon(Icons.add),onPressed: () {print("add press ");},),//其他菜单栏bottomNavigationBar: BottomAppBar(//悬浮按钮 与其他菜单栏的结合方式shape: CircularNotchedRectangle(),// FloatingActionButton和BottomAppBar 之间的差距notchMargin: 6.0,color: Colors.white,child: Row(mainAxisSize: MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.spaceAround,children: <Widget>[buildBotomItem(currentIndex, 0, Icons.home, "首页"),buildBotomItem(currentIndex, 1, Icons.library_music, "发现"),buildBotomItem(currentIndex, -1, null, "发现"),buildBotomItem(currentIndex, 2, Icons.email, "消息"),buildBotomItem(currentIndex, 3, Icons.person, "我的"),],),),));}// ignore: slash_for_doc_comments/*** @param selectIndex 当前选中的页面* @param index 每个条目对应的角标* @param iconData 每个条目对就的图标* @param title 每个条目对应的标题*/buildBotomItem(int selectIndex, int index, IconData iconData, String title) {//未选中状态的样式TextStyle textStyle = TextStyle(fontSize: 12.0,color: Colors.grey);MaterialColor iconColor = Colors.grey;double iconSize=20;EdgeInsetsGeometry padding =  EdgeInsets.only(top: 8.0);if(selectIndex==index){//选中状态的文字样式textStyle = TextStyle(fontSize: 13.0,color: Colors.blue);//选中状态的按钮样式iconColor = Colors.blue;iconSize=25;padding =  EdgeInsets.only(top: 6.0);}Widget padItem = SizedBox();if (iconData != null) {padItem = Padding(padding: padding,child: Container(color: Colors.white,child: Center(child: Column(children: <Widget>[Icon(iconData,color: iconColor,size: iconSize,),Text(title,style: textStyle,)],),),),);}Widget item = Expanded(flex: 1,child: new GestureDetector(onTap: () {if (index != currentIndex) {setState(() {currentIndex = index;});}},child: SizedBox(height: 52,child: padItem,),),);return item;}
}

//子页面
class ChildItemView extends StatefulWidget {String _title;ChildItemView(this._title);@override_ChildItemViewState createState() => _ChildItemViewState();
}class _ChildItemViewState extends State<ChildItemView> {@overrideWidget build(BuildContext context) {return Container(child: Center(child: Text(widget._title)),);}
}

flutter BottomAppBar 实现不规则底部导航栏相关推荐

  1. 【Flutter】StatefulWidget 组件 ( 底部导航栏组件 | BottomNavigationBar 组件 | BottomNavigationBarItem 组件 | 选项卡切换 )

    文章目录 一.BottomNavigationBar 组件 二.BottomNavigationBarItem 组件 三.BottomNavigationBar 底部导航栏代码示例 四.BottomN ...

  2. Flutter学习日记之底部导航栏BottomNavigationBar组件的使用

    本文地址:https://blog.csdn.net/qq_40785165/article/details/116953235,转载需附上此地址 大家好,我是小黑,一个还没秃头的程序员~~~ 空袋子 ...

  3. Flutter仿闲鱼底部导航栏实现

    概述 本文主要实现一个仿闲鱼底部导航栏实现,这种效果在项目中经常用到,接下来我们就从头开始实现. 仿闲鱼底部导航栏 要实现闲鱼底部导航栏的效果我们需要使用到BottomNavigationBar和Fl ...

  4. Flutter 凸起效果底部导航栏一

    大多app中都会带有底部导航栏,系统默认自带的导航条不够新颖.今天我们改造一下导航条,将中间的按钮起到凸起的效果,特别有的app,中间常用扫一扫功能. Flutter为我们提供了一个控件BottomN ...

  5. flutter TabBar 底部导航栏

    更多文章请查看 lutter从入门 到精通 实现底部导航栏并点击切换页面可简述为有三种方式 TabBar + TabBarView BottomNavigationBar + BottomNaviga ...

  6. flutter底部导航栏

    更多文章请查看 lutter从入门 到精通 实现底部导航栏并点击切换页面可简述为有三种方式 TabBar + TabBarView BottomNavigationBar + BottomNaviga ...

  7. android仿咸鱼底部导航栏,Flutter沉浸式状态栏/AppBar导航栏/仿咸鱼底部凸起导航栏效果...

    如下图:状态栏是指android手机顶部显示手机状态信息的位置. android 自4.4开始新加入透明状态栏功能,状态栏可以自定义颜色背景,使titlebar能够和状态栏融为一体,增加沉浸感. 如上 ...

  8. 【Flutter】底部导航栏页面框架 ( BottomNavigationBar 底部导航栏 | PageView 滑动页面 | 底部导航与滑动页面关联操作 )

    文章目录 一.BottomNavigationBar 底部导航栏 二.PageView 滑动页面 三.BottomNavigationBar 与 PageView 关联 四.完整代码示例 1.核心导航 ...

  9. 【Flutter】底部导航栏实现 ( BottomNavigationBar 底部导航栏 | BottomNavigationBarItem 导航栏条目 | PageView )

    文章目录 一.Scaffold 组件 二.底部导航栏整体架构 三.BottomNavigationBar 底部导航栏 四.BottomNavigationBarItem 导航栏条目 五.PageVie ...

最新文章

  1. 一文深入浅出cv中的Attention机制
  2. 专家系统出现的计算机应用阶段,接本第一二章历年考题08-12
  3. ADO.NET中的五个主要对象
  4. php openssl加密数据长度,PHP使用openssl解密数据(用mcrypt加密)
  5. python基础课程3(看代码看注释)--数据库基本操作(mysql)
  6. echarts柱状图x轴文字纵向显示
  7. Python 基础之在ubuntu系统下安装双版本python
  8. 织梦 html5视频显示问题,织梦网站HTML5 video视频播放器(不用安装插件)
  9. OpenGL基础20:镜面光照
  10. echarts Map(地图) 不同颜色区块显示
  11. [转] 驱动模拟键盘鼠标
  12. 通过I2C读取显示器的EDID信息
  13. 100句充满智慧的人生格言
  14. Docker的基本使用
  15. Acwing LeetCode 题目分类——配套基础课进阶课
  16. 传统的招投标or在线招投标
  17. 艾兰岛编辑器-无法通过的屏障
  18. 武林外传电影版java,武林外传经典台词
  19. c3p0存在严重bug
  20. 小程序高级电商前端第2周深入理解REST API开发规范 开启三端分离编程之旅<二>----scroll-view组件的灵活应用、async和await问题探讨、spu-scroll自定义组件

热门文章

  1. 用了Python,老板再也不用担心我写不了CUDA了!
  2. ICCV 2019 VisDrone挑战赛冠军方案解读
  3. 强烈推荐!商汤-港中文MMLab开源图像视频超分辨率工具箱MMSR
  4. 从零开始拿到了Kaggle竞赛冠军
  5. 刷新记录! CVPR2021全新目标检测机制达到SOTA!
  6. 主成分分析降维(MNIST数据集)
  7. ipqc异常处理流程图_IPQC巡检流程.七大手法.八大原则.九大步骤
  8. influxdb聚合函数JAVA_InfluxDB 聚合函数实用案例
  9. 结构体前面加星号_C语言中带星号的类型指针有哪些特性
  10. 读取properties文件,中文乱码