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

解决方式:

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

 

点赞