【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏_第1页
【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏_第2页
【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏_第3页
【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏_第4页
【移动应用开发技术】怎么在flutter中利用BottomAppBar实现不规则底部导航栏_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】怎么在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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论