如果你以为设置preferredSize
就可以,那真的是太天真了。preferredSize可以设置appbar的高度,但是无法让appbar的内容完全显示出来,因为appbar源码中kToolbarHeight
常量值为56,看源码注释即可
/// The height of the toolbar component of the [AppBar].
const double kToolbarHeight = 56.0;
所以你无论怎么设置preferredSize
,appbar中的的组件只显示高度范围56
两种方式来解决
- 自定义appbar
- 使用appbar的flexibleSpace属性
/// This widget is stacked behind the toolbar and the tab bar. It's height will
/// be the same as the app bar's overall height.
///
/// A flexible space isn't actually flexible unless the [AppBar]'s container
/// changes the [AppBar]'s size. A [SliverAppBar] in a [CustomScrollView]
/// changes the [AppBar]'s height when scrolled.
///
/// Typically a [FlexibleSpaceBar]. See [FlexibleSpaceBar] for details.
final Widget flexibleSpace;