簡體   English   中英

擴展的小部件拋出“RenderBox沒有布局”異常

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

ListViewScrollView一起使用時,使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM