Reputation: 697
I have a Row which contains some containers as children like this:
Row(
children: addEntities(),
),
where addEntities return a list of containers...
Now i want to scroll that row horizontally .. so i tried this:
ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Row(
children: addEntities(),
),
],
),
but this now displays nothing and return this error:
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.
I tried alot of options from this question: Flutter Listview Scrollable Row
But none worked ...
How to solve this problem? I want the row to scroll horizontally?
my full code:
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),
),
],
),
),
Upvotes: 2
Views: 2356
Reputation: 277027
On Row
, set mainAxisSize
to MainAxisSize.min
or wrap it into an IntrinsicWidth
widget.
By default, Row
fill the horizontal space, which conflicts with ListView
in horizontal mode. ListView
will use the horizontal size of its children to determine if it's scrollable or not.
Upvotes: 1