Flutter 如何将容器垂直拉伸到最大屏幕?
但随后我收到以下错误: 在performLayout()期间引发了以下断言:Flutter 如何将容器垂直拉伸到最大屏幕?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,但随后我收到以下错误: 在performLayout()期间引发了以下断言: BoxConstraints强制无限高。使用扩展的小部件包装容器,并完全移除高度 Container( width: 100.00, height: double.infinity, color: Colors.red, 展开的小部件沿主轴填充行或列的子项的可用空间。要实现此目的,您可以: 1) 使用名为Expandedwidget的小部件 Expanded
BoxConstraints强制无限高。使用扩展的小部件包装容器,并完全移除高度
Container(
width: 100.00,
height: double.infinity,
color: Colors.red,
展开的小部件沿主轴填充行或列的子项的可用空间。要实现此目的,您可以: 1) 使用名为
Expanded
widget的小部件
Expanded(
child: Container(
width: 100.00,
color: Colors.red,
),
),
将高度指定给的正确方法是计算
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
// give it a width equals to the device screen
width: MediaQuery.of(context).size.width,
// give it a height equals to the device screen
height: MediaQuery.of(context).size.height,
color: Colors.red,
),
])),
));
final mediaQuery = MediaQuery.of(context);
2。声明AppBar小部件,并在Scaffold App Bar中使用相同的App Bar实例
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
// give it a width equals to the device screen
width: MediaQuery.of(context).size.width,
// give it a height equals to the device screen
height: MediaQuery.of(context).size.height,
color: Colors.red,
),
])),
));
final mediaQuery = MediaQuery.of(context);
3。使用计算高度
final PreferredSizeWidget appBar = AppBar(
title: Text('Home'),
);
Container(
width: mediaQuery.size.width,
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top),
color: Colors.red,
),