[英]Expanded Widget throws “ RenderBox was not laid out” Exception
我是新来的人。 我正在设置一个包含ListView Widget的Expanded Widget。 Expanded Widget位于Column Widget中。 但是运行代码会给出“RenderBox没有布局”的例外情况。 我该如何修复代码?
Widget build(BuildContext context) {
return ListView(
children: products
.map(
(element) => Card(
child: Column(
children: <Widget>[
Text(element)
],
),
),
)
.toList(),
);
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10.0),
child: ProductControl(_addProduct),
),
Expanded(
child: Products(_products),
)
],
);
}
错误:
I/flutter ( 9914): Another exception was thrown: RenderBox was not laid out: RenderFlex#e84ab relayoutBoundary=up2 NEEDS-PAINT
与ListView
或ScrollView
一起使用时,使用Flexible
而不是Expanded
。
您可以在固定宽度和高度的容器中使用Flexible或Try包装
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(10.0),
child: ProductControl(_addProduct),
),
container(
width:300,//set as required
height:300,
child: Expanded(
child: Products(_products),
),
),
],
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.