版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么在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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国银杏叶提取物行业竞争格局及发展前景预测研究报告(2024-2030)
- 中国重庆市网红经济行业市场现状供需分析及市场深度研究发展前景及规划可行性分析研究报告(2024-2030版)
- 中国酒吧连锁行业市场发展现状及竞争格局与投资前景研究报告(2024-2030)
- 中国输配电行业十四五现状供需分析及市场深度研究发展前景及规划可行性分析研究报告(2024-2030)
- 中国越野汽车市场调研及发展策略研究报告(2024-2030)
- 2024-2030年中国金融IT行业发展分析及发展前景与趋势预测研究报告
- 2024-2030年中国营养性添加剂行业市场现状分析及竞争格局与投资发展研究报告
- 2024-2030年中国纳米塑料行业发展分析及发展前景与趋势预测研究报告
- 2024-2030年中国狗狗香波浴液行业市场现状分析及竞争格局与投资发展研究报告
- 2024届山东省淄博市临淄区重点达标名校中考猜题英语试卷含答案
- GB/T 43641-2024生物学全同胞关系鉴定技术规范
- 2023水利工程设计变更报告编制导则
- 工程伦理-工程案例分析
- (高清版)WS-T 820-2023 医院电力系统消防安全管理标准
- 教师招考教育综合知识试题及答案
- 结构动力学ch6(风振响应)课件
- 多糖对食品的保鲜作用
- 哈尔滨太阳岛风景名胜区总体规划
- GB 38031-2020 电动汽车用动力蓄电池安全要求
- Bill of lading 提单 模板.doc
- 铆工技能比赛实施方案.doc
评论
0/150
提交评论