title: 'PreferredSize' description: '' type: widget

PreferredSize

此控件不对其子控件施加任何约束,并且不以任何方式影响孩子的布局。

此控件对自定义AppBar.bottomAppBar非常有用。

自定义AppBar,也可以直接设置AppBar的高度(PreferredSize子控件为AppBar)

Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(200),
          child: Container(
            color: Colors.blue,
          ),
        ),
        body: Test1(),
      )

image-20200529184724974

AppBar.bottom通常是TabBar等,通过PreferredSize可设置为任意组件:

Scaffold(
  appBar: AppBar(
    bottom: PreferredSize(
      preferredSize: Size.fromHeight(48),
      child: Container(
        height: 48,
        color: Colors.red,
      ),
    ),
  ),
  body: Test1(),
)

image-20200529185156883