列表视图中的行未显示

时间:2019-02-18 11:16:32

标签: dart flutter

我有一个Row,其中包含一些像这样的子容器:

Row(
    children: addEntities(),
),

其中addEntities返回容器列表...

现在我想水平滚动该行..所以我尝试了这个:

ListView(
    scrollDirection: Axis.horizontal,
    children: <Widget>[
    Row(
           children: addEntities(),
       ),
    ],
),

但是现在不显示任何内容并返回此错误:

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: Horizontal viewport was given unbounded width.
flutter: Viewports expand in the scrolling direction to fill their container.In this case, a horizontal
flutter: viewport was given an unlimited amount of horizontal space in which to expand. This situation
flutter: typically happens when a scrollable widget is nested inside another scrollable widget.
flutter: If this widget is always nested in a scrollable widget there is no need to use a viewport because
flutter: there will always be enough horizontal space for the children. In this case, consider using a Row
flutter: instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
flutter: the width of the viewport to the sum of the widths of its children.

我尝试了以下问题的许多选择:Flutter Listview Scrollable Row

但是没有一个...

如何解决这个问题?我希望该行水平滚动吗?

我的完整代码:

GestureDetector(
  onTap: () {
},
child: new Row(
children: <Widget>[

entitiesFilter.isEmpty
     ? Text( uiLabels['filterSearchOrg'] [globals.currentLang],
       style: TextStyle( fontSize: ScreenUtil().setSp( fontSize['15-2'] [globals.platform]),
      ),
    )
  : SingleChildScrollView(
     scrollDirection: Axis.horizontal,
       child: IntrinsicHeight(
          child: Row(
             crossAxisAlignment: CrossAxisAlignment.stretch,
             children: addEntities(),
      ),
    ),
  ),
  Spacer(),
  new Icon(
     CustomFont.arrow_bottom_1,
     size: 7.0,
     color: Color(0xffBAB9BD),
   ),
  ],
 ),
),

1 个答案:

答案 0 :(得分:0)

Row上,将mainAxisSize设置为MainAxisSize.min或将其包装到IntrinsicWidth小部件中。

默认情况下,Row填充水平空间,在水平模式下与ListView冲突。 ListView将使用其子元素的水平大小来确定其是否可滚动。