Flutter AppBar、SliverAppBar 属性及描述

9 min read

AppBar 位置是固定在应用最上面的,而 SliverAppBar 是可以跟随内容滚动的。

属性名 类型 说明 默认值 取值
leading Widget 在标题前面显示的一个组件,在首页通常显示应用的 logo;在其他界面通常显示为返回按钮 null
title Widget Toolbar 中的主要内容,通常显示为当前界面的标题文字 null
actions List Widget 列表,ToolBar 中所显示菜单。对于常用的菜单,通常使用 IconButton 来表示,对于不常用的菜单使用 PopupMenuButton 来显示为三个点,点击后弹出耳机菜单 null
bottom PreferredSizeWidget 通常是 TabBar,用来在 Toolbar 标题下面显示一个 Tab 导航栏 null
elevation double Material Design 设计中组件的 z 坐标顺序,对于可滚动的 SliverAppBar,当 SliverAppBar 和内容同级的时候,该值为 0,当内容滚动 SliverAppBar 变为 Toolbar 的时候,修改 elevation 的值 4
flexibleSpace Widget 一个显示在 AppBar 下方的组件,高度和 AppBar 高度一样,可以实现一些特殊的效果,该属性通常在 SliverAppBar 中使用
backgroundColor Color 背景色 ThemeData.primaryColor
brightness Brightness AppBar 的亮度,有白色和黑色两种主题 ThemeData.primaryColorBrightness
iconTheme IconThemeData AppBar 上图标的颜色、透明度和尺寸信息 ThemeData.primaryIconTheme
textTheme TextTheme AppBar 上的文字样式 Theme.primaryTextTheme
centerTitle bool 标题是否居中 true