




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏
今天就跟大家聊聊有关怎么在flutter中利用BottomAppBar实现不规则底部导航栏,可能很多人都不太了解,为了让大家更加了解,在下给大家总结了以下内容,希望大家根据这篇文章可以有所收获。实现底部导航栏并点击切换页面可简述为有三种方式TabBar+TabBarViewBottomNavigationBar+BottomNavigationBarItem自定义BottomAppBar在这里使用BottomAppBar来实现/**
*
有状态StatefulWidget
*
继承于
StatefulWidget,通过
State
的
build
方法去构建控件
*/
class
BotomeMenumBarPage
extends
StatefulWidget
{
////通过构造方法传值
BotomeMenumBarPage();
//主要是负责创建state
@override
BotomeMenumBarPageState
createState()
=>
BotomeMenumBarPageState();
}
/**
*
在
State
中,可以动态改变数据
*
在
setState
之后,改变的数据会触发
Widget
重新构建刷新
*/
class
BotomeMenumBarPageState
extends
State<BotomeMenumBarPage>
{
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:
<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()
=>
_ChildItemVi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 华图教师面试说课课件
- 贵港高考数学试卷
- 槐荫区教师小学数学试卷
- 杭州文晖中学数学试卷
- 2025年广东省深圳建文外国语学校物理高一第二学期期末考试模拟试题含解析
- 2025年地板行业市场专项调研及投资前景可行性预测报告
- 2025年中国海参养殖行业市场调研分析及投资战略咨询报告
- 中国激光振镜控制系统行业市场发展监测及投资潜力预测报告
- 健康研究视频课件下载网
- 水利审计报告
- 提高情商的培训课件
- JJG 597-2025交流电能表检定装置检定规程
- 2025年广州市中考物理试题(含答案)
- 2024年漳州市常山开发区招聘笔试真题
- 2024年09月年中国农业发展银行江苏省分行秋季校园招聘(86人)笔试历年参考题库附带答案详解
- 2025年江苏省扬州市中考作文4篇范文:“尊重”“诚实”“创造性”“美好生活”
- 2025年辅警招聘考试试题库含完整答案
- 2025年吉林省中考语文试卷及答案
- 2024-2025学年度天津铁道职业技术学院单招《语文》真题附答案详解(突破训练)
- 快递行业市场发展分析及投资前景研究报告2025-2028版
- 礼仪培训ptt课件
评论
0/150
提交评论