RenderFlex children have non-zero flex but incoming width constraints are unbounded.

问题代码:

                  new Expanded(
                      flex: 80,
                      child: new Container(
                          padding: EdgeInsets.fromLTRB(0.0, 50.0, 0.0, 50.0),
                          color: Colors.deepPurple,
                          child: new ListView(
                              scrollDirection: Axis.horizontal,
                              children: listRooms))),
复制代码
  Widget buildListTile(BuildContext context, int roomNum) {
    return new Container(
//        constraints: BoxConstraints.tightFor(width:111.0,height:111.0),
        child: Column(children: <Widget>[
          new Text("房间号 1"),
          new Row(children: <Widget>[
            new Expanded(child: new Text("左边")),
            new Expanded(child: new Text("中间")),
            new Expanded(child: new Text("右边")),
          ],)
        ],),
        color: Colors.purple,
    );
  }
复制代码

报错:

复制代码
Performing hot reload...
I/flutter (12146): buildbuildbuildbuildbuildbuildbuildbuild
I/flutter (12146): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (12146): The following assertion was thrown during performLayout():
I/flutter (12146): RenderFlex children have non-zero flex but incoming width constraints are unbounded.
I/flutter (12146): When a row is in a parent that does not provide a finite width constraint, for example if it is in a
I/flutter (12146): horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a
I/flutter (12146): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (12146): space in the horizontal direction.
I/flutter (12146): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (12146): cannot simultaneously expand to fit its parent.
I/flutter (12146): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (12146): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (12146): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (12146): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (12146): constraints provided by the parent.
I/flutter (12146): The affected RenderFlex is:
I/flutter (12146):   RenderFlex#a72d0 relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (12146): The creator information is set to:
I/flutter (12146):   Row ← Column ← DecoratedBox ← Container ← RepaintBoundary-[<0>] ←
I/flutter (12146):   NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← SliverList ←
I/flutter (12146):   MediaQuery ← SliverPadding ← Viewport ← ⋯
I/flutter (12146): See also: https://flutter.io/layout/
I/flutter (12146): If this message did not help you determine the problem, consider using debugDumpRenderTree():
I/flutter (12146):   https://flutter.io/debugging/#rendering-layer
I/flutter (12146):   http://docs.flutter.io/flutter/rendering/debugDumpRenderTree.html
I/flutter (12146): If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
I/flutter (12146):   https://github.com/flutter/flutter/issues/new
复制代码

解决方式:

  去掉上面的注释就好了,但那只是加了一个限制,让框架知道怎么布局对界面显示可能不会有影响

 

posted on   --LP--  阅读(5245)  评论(0编辑  收藏  举报

(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示