This is my code:
@override
Widget build(BuildContext context) {
return new Material(
color: Colors.deepPurpleAccent,
child: new Column(
This answer is based on the north of the @CopsOnRoad
This happens because the ListView/GridView widget has no parent to take its size , so its height is infinite and is the flutter does not know the height of the ListView and cannot render.
Solution one: fixed height
Wrap it up directly with the Container or SizedBox to write the dead height.
Column(
children: [
SizedBox(
height: 400, // fixed height
child: ListView(...),
),
],
)
This is fine, but if the height needs to be adaptive, it will not work if you write it.
Solution two: shrinkWrap: true
Try shrinkWrap: true with physics: ScrollPhysics() for scrolling
shrinkWrap: true is a bit like in android's wrap_content.
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: ScrollPhysics()
...
However, after compiling, you will find a long yellow warning at the bottom of the page.
So still can't
Solution three: Expanded or Flexible
Flexible Is a flexible layout in flutter, equivalent to LinearLayout in android.
There is one in Flexible flex The attribute, equal to layout_weight, takes up all the remaining space.
So, we can wrap the ListView with Flexible.
Column(
children: [
Expanded(
child: ListView(...),
),
],
)
This answer based :Vertical viewport was given unbounded height.