千家信息网

flutter Bottom AppBar如何实现不规则底部导航栏

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,flutter Bottom AppBar如何实现不规则底部导航栏,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。实现底部
千家信息网最后更新 2026年11月02日flutter Bottom AppBar如何实现不规则底部导航栏

flutter Bottom AppBar如何实现不规则底部导航栏,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

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

TabBar + TabBarView BottomNavigationBar + BottomNavigationBarItem 自定义 BottomAppBar

在这里 使用 BottomAppBar 来实现

/** * 有状态StatefulWidget * 继承于 StatefulWidget,通过 State 的 build 方法去构建控件 */class BotomeMenumBarPage extends StatefulWidget { ////通过构造方法传值 BotomeMenumBarPage(); //主要是负责创建state @override BotomeMenumBarPageState createState() => BotomeMenumBarPageState();}/** * 在 State 中,可以动态改变数据 * 在 setState 之后,改变的数据会触发 Widget 重新构建刷新 */class BotomeMenumBarPageState extends State { BotomeMenumBarPageState(); @override void initState() { ///初始化,这个函数在生命周期中只调用一次 super.initState(); } @override Widget 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: [ 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: [ 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 { @override Widget build(BuildContext context) { return Container( child: Center(child: Text(widget._title)), ); }}

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

页面 按钮 状态 导航 条目 样式 底部 动态 数据 方式 方法 菜单 首页 帮助 不规则 清楚 之间 位置 内容 函数 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广东万易互联网科技有限公司惠州分公司 中国互联网科技股 互联网科技缩写 米客互联网科技 互联网 新科技 安控科技rtu产品工业互联网 互联网科技实习生岗位职责 阿里互联网科技公司 栖莱科技互联网股份有限公司 宜昌元轩互联网科技有限公司 广州市恰铎互联网科技有限公司 世界互联网领先科技成果获奖 山东星卡互联网科技有限公司官网 智帮互联网科技公司最近动向 互联网科技资金流入 普陀区互联网教育科技管理办法 第三届互联网大会安防黑科技 杭州融税互联网科技有限公司 互联网科技大佬云集 伍佰万互联网科技是干嘛的 互联网是不是新科技 互联网金融与金融科技 互联网 科技创新 为想互联网科技 齐家互联网科技有限公司 甘肃拓世互联网科技有限公司 互联网企业和科技型企业 消费医药和互联网科技 科技赋能视角下互联网保险发展 本届互联网大会上的黑科技
0