列表视图中的行未显示
Posted
技术标签:
【中文标题】列表视图中的行未显示【英文标题】:Row inside a list view is not shown 【发布时间】:2019-07-11 18:21:03 【问题描述】:我有一个 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),
),
],
),
),
【问题讨论】:
用 SingleChildScrollView 而不是 ListView 包装它 @salihguler 我做了 .. 但无法滚动 @salihguler 我会收到此错误:在布局期间抛出以下消息 A RenderFlex 在右侧溢出了 38 个像素。它不会滚动 等等,要滚动行吗? 这完全取决于您要实现的 UI。我建议提出一个标题类似于“如何在 Flutter 中进行嵌套滚动?”的新问题。并包含所需行为的视觉示例。 【参考方案1】:在Row
上,将mainAxisSize
设置为MainAxisSize.min
或将其包装到IntrinsicWidth
小部件中。
默认情况下,Row
填充水平空间,这与水平模式下的ListView
冲突。 ListView
将使用其子项的水平大小来确定它是否可滚动。
【讨论】:
我刚刚发布了完整的小部件树.. 我尝试按照您的建议将 mainAxisSize: MainAxisSize.min 添加到行中.. 但我现在什么都没有出现! 将行换成SizebBox
,并给出一些高度和宽度。以上是关于列表视图中的行未显示的主要内容,如果未能解决你的问题,请参考以下文章