Scaleup Guide
Fix Flutter 'Vertical viewport was given unbounded height'
Direct Answer
This guide gives a simple overview of fix flutter 'vertical viewport was given unbounded height'. If you need help turning the idea into a website, app, or business system, the related Scaleup Infotech services are listed below.
Putting a scrollable ListView directly inside a Column confuses Flutter: the Column offers infinite height, but the ListView needs a bounded height to know how big to be. You have to constrain it.
The Error
Vertical viewport was given unbounded height. RenderBox was not laid out.
Fix 1: Wrap the ListView in Expanded
Column(
children: [
const Header(),
Expanded( // gives the ListView a bounded height
child: ListView(children: items),
),
],
)Fix 2: shrinkWrap for a Short, Non-Scrolling List
ListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: items, // sizes to content; let the parent scroll
)Don't shrinkWrap Big Lists
shrinkWrap measures every child up front — fine for 5 items, terrible for 5,000. For long lists, use Expanded or a CustomScrollView with slivers.
