flutter之AppBar

本文详细介绍了Flutter框架中的AppBar组件,包括其构造函数、常用属性及如何使用。AppBar是Material风格的应用栏,由工具栏等Widget构成,常用于Scaffold.appBar属性,置于屏幕顶部。文章还解释了leading、title、actions等关键属性的用法。

1 AppBar

一个典型的AppBar,带有标题、操作和溢出的下拉菜单。AppBar  Material风格应用栏,有工具栏和其他的Widget构成 应用栏通常用于Scaffold.appBar属性,该属性将应用栏放置在屏幕顶部的固定高度小部件中。对于可滚动的应用栏,请参阅SliverAppBar,它将一个AppBar嵌入到一个条子中,以便在CustomScrollView中使用。

2 构造函数

AppBar({
     Key key,
     this.leading,
     this.automaticallyImplyLeading = true,
     this.title,
     this.actions,
     this.flexibleSpace,
     this.bottom,
     this.backgroundColor,
     this.brightness,
     this.iconTheme,
     this.textTheme,
     this.primary = true,
     this.centerTitle,
     this.titleSpacing = NavigationToolbar.kMiddleSpacing,
     this.toolbarOpacity = 1.0,
     this.bottomOpacity = 1.0,
 })

3 常用属性

3.1 tleading:在标题前面显示的一个控件,在首页通常显示应用的 logo;在其他界面通常显示为返回按钮

leading: IconButton(
     icon: Icon(Icons.menu),
     onPressed: () {},
 ),

3.2 title:标题,通常显示为当前界面的标题文字,可以放组件

title: "AppBarWidget",

3.3 actions:通常使用 IconButton 来表示,可以放按钮组

actions: <Widget>[
     IconButton(
         icon: Icon(Icons.search),
         onPressed: () {},
     ),
     IconButton(
         icon: Icon(Icons.more_horiz),
         onPressed: () {},
     )
],

3.4 bottom:通常放 tabBar,标题下面显示一个 Tab 导航栏

bottom:<Widget>[],

3.5 backgroundColor:导航背景颜色

backgroundColor: Colors.redAccent,

3.6 centerTitle: 标题是否居中显示,默认值根据不同的操作系统,显示方式不一样

centerTitle: true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值