How to solve ʺVertical viewport was given unbounded heightʺ Error on Flutter

While adding Listview inside Scroll view or building grid layout, you may encounter "Vertical viewport was given unbounded height" Error on Flutter. This caused, when there is the unbounded height on the parent widget. See the example below:

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

ListView(
  shrinkWrap: true,
  children: [
        
  ],
)

Container(
  height: 500,
  child:ListView(
      children: [
          
      ],
  ),
)

OR

SizedBox(
  height: MediaQuery.of(context).size.height,
  child:ListView(
      children: [
          
      ],
  ),
)

Expanded(
  child:ListView(
      children: [
          
      ],
  ),
)

In this way, you can solve the "Vertical viewport was given unbounded height" error on Flutter.

No any Comments on this Article


Please Wait...