I am trying to write an App using Flutter, but every time I add a ListView, the following exception is thrown at runtime: Vertical viewport was given unbounded height<
Just wrap the ListView with Expanded widget.
new Expanded(
child: new ListView(
.....
)
);
This tells the ListView to take width and height as much as it can.
Just Wrap into Container and give it an height
new Container(
height: 44.0,
child: new ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
new RaisedButton(
onPressed: null,
child: new Text("Facebook"),
),
new Padding(padding: new EdgeInsets.all(5.00)),
new RaisedButton(
onPressed: null,
child: new Text("Google"),
)
],
),
)
You can fix the exception by specifying shrinkWrap = true
for your ListView
.
ListView(
shrinkWrap: true,
children...
)
This is stated in the exception message. The reason is stated in the exception messag as well.
In this specific case I am not particularly sure which Widget
in the tree causes this, but I think that it is not relevant. I do not know what your Container
about the ListView
is about. I would start by wrapping it around the Column
, but shrinkWrap
should do the trick.