Download StackFood Multi Restaurant, Food Delivery App with Laravel Admin and Restaurant Panel Buy Full App on $79
Download FlutKit - Flutter UI Kit Most beautiful Flutter UI Kit with 20+ Full App, 450+ Screens. Buy Full Kit on $39
Download Fluxstore Multi Vendor WooCommerce/Dokan Plugin compatible WordPress eCommerce Flutter App. Buy Full App on $79

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:

Error Message:

══╡ 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.

Solution One: Use Shrinkwrap: true on ListVew() Widget:

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

Set Bounded Height on Parent Widget using Container or SizedBox():

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

OR

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

Wrap ListView with Exampanded Wiget:

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...