Fix: RenderBox was not laid out in Flutter
The complete guide to diagnosing and fixing the 'RenderBox was not laid out' error in Flutter, with real examples and InkPal's automated fix.
Fix: RenderBox was not laid out
If you've worked with Flutter for more than a week, you've seen this error:
RenderBox was not laid out: RenderRepaintBoundary#a5765 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
It's one of the most common Flutter errors, and it usually means a widget has unbounded constraints — it doesn't know how big to be.
Why It Happens
Flutter's layout system works in three phases: constraints go down, sizes go up, positions are set. When a widget receives unbounded constraints (e.g., inside a Column or ListView) and doesn't have an intrinsic size, the render box can't determine its layout.
The Most Common Triggers
1. ListView inside Column without bounds
// BAD — ListView has unbounded height inside Column
Column(
children: [
Text('Header'),
ListView.builder( // Unbounded!
itemCount: 100,
itemBuilder: (ctx, i) => ListTile(title: Text('Item $i')),
),
],
)Fix: Wrap the ListView in Expanded or SizedBox:
// GOOD
Column(
children: [
Text('Header'),
Expanded(
child: ListView.builder(
itemCount: 100,
itemBuilder: (ctx, i) => ListTile(title: Text('Item $i')),
),
),
],
)2. Row with unbounded children
// BAD — Both children want infinite width
Row(
children: [
Text('A very long text that keeps going'),
Text('Another very long text'),
],
)Fix: Use Flexible or Expanded:
// GOOD
Row(
children: [
Expanded(child: Text('A very long text that keeps going')),
Expanded(child: Text('Another very long text')),
],
)3. CustomScrollView with unconstrained Sliver
This happens when a SliverList or SliverGrid is placed inside a widget that doesn't provide scroll constraints.
InkPal's Automated Fix
InkPal can detect and fix this error automatically:
# InkPal detects the error at runtime
inkpal.lookup_error("RenderBox was not laid out")
# Returns: explanation + fix steps + widget tree location
# Or let the self-healing engine fix it
inkpal.self_heal()
# Adds Expanded/Flexible wrapper automaticallyPrevention Checklist
- Never put scrollable widgets inside unbounded parents without constraints
- Always use
ExpandedorFlexiblewhen children compete for space - Use
shrinkWrap: trueonly for small lists (performance cost) - Check the widget inspector for constraint violations
This error is indexed in InkPal's error database. Use /errors to look up any Flutter error instantly.