[英]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.