




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么在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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 探秘古诗词之美
- 四级英语全攻略
- 山西工程技术学院《机械工程英语》2023-2024学年第二学期期末试卷
- 天津音乐学院《汽车理论A》2023-2024学年第二学期期末试卷
- 南京旅游职业学院《游泳实践教学》2023-2024学年第二学期期末试卷
- 辽宁省大连市普兰店市第六中学2024-2025学年高三下第一次测试语文试题含解析
- 江西省丰城市第九中学2025届初三下学期3月第二次月考生物试题含解析
- 山东省临沂市兰山区2025届小学六年级数学毕业检测指导卷含解析
- 南华县2025届数学四下期末监测模拟试题含解析
- 上海财经大学浙江学院《药用辅料学》2023-2024学年第二学期期末试卷
- 2025年电子信息工程专业考试卷及答案
- 广东省珠海市2024-2025学年高二下学期期中教学质量检测英语试题(原卷版+解析版)
- 北京2025年中国环境监测总站招聘(第二批)笔试历年参考题库附带答案详解
- 美国加征关税从多个角度全方位解读关税课件
- “皖南八校”2024-2025学年高一第二学期期中考试-英语(译林版)及答案
- 委托融资协议书范本
- 定额〔2025〕1号文-关于发布2018版电力建设工程概预算定额2024年度价格水平调整的通知
- 2021年妊娠期血压管理中国专家共识
- 一种基于STM32的智能门锁系统的设计-毕业论文
- 控机床故障诊断与维修几例
- 上海建设工程通用硅酸盐水泥质量检验报告 - 上海水泥行业协会
评论
0/150
提交评论