PreferredSize
此控件不对其子控件施加任何约束,并且不以任何方式影响孩子的布局。
常用来自定义AppBar和AppBar.bottom(PreferredSize子控件为AppBar或者AppBar.bottom)
Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(200),
child: Container(
color: Colors.blue,
),
),
body: Test1(),
)
AppBar.bottom通常是TabBar等,通过PreferredSize可设置为任意组件:
Scaffold(
appBar: AppBar(
bottom: PreferredSize(
preferredSize: Size.fromHeight(48),
child: Container(
height: 48,
color: Colors.red,
),
),
),
body: Test1(),
)
本文详细介绍了PreferredSize在Flutter框架中的使用方法,特别是如何利用它来自定义AppBar和AppBar.bottom的大小,实现对任意组件的高度定制。通过具体的代码示例,展示了PreferredSize如何帮助开发者灵活调整界面布局。
213

被折叠的 条评论
为什么被折叠?



