What causes "A RenderFlex overflowed by N pixels"?
RenderFlex overflow happens when the total size of children in a Row or Column exceeds the available space. Fix with SingleChildScrollView, Expanded, Flexible, or by reducing content.
Diagnose and fix common Flutter layout and rendering problems
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Layout bugs are among the most common issues Flutter developers face. From the dreaded "RenderFlex overflowed" yellow-and-black striped warning to invisible widgets and unexpected spacing, layout problems can be frustrating to debug. This lesson teaches you to systematically identify and fix the most frequent layout issues using Flutter DevTools and proven debugging techniques.
1// ══════════════════════════════════════2// TOP 5 LAYOUT BUGS AND THEIR FIXES3// ══════════════════════════════════════45// ── BUG 1: RenderFlex Overflowed ──6// ERROR: "A RenderFlex overflowed by 42 pixels on the bottom"7// CAUSE: Content exceeds available space in a Row or Column89// BAD:10Column(11children: [12Container(height: 400, color: Colors.blue),13Container(height: 400, color: Colors.red), // Overflows!14],15)1617// FIX: Wrap in SingleChildScrollView or use Expanded/Flexible18SingleChildScrollView(19child: Column(20children: [21Container(height: 400, color: Colors.blue),22Container(height: 400, color: Colors.red), // Scrollable now23],24),25)2627// Or use Flexible to share space:28Column(29children: [30Expanded(child: Container(color: Colors.blue)),31Expanded(child: Container(color: Colors.red)),32],33)3435// ── BUG 2: Unbounded Height/Width ──36// ERROR: "Vertical viewport was given unbounded height"37// CAUSE: ListView inside Column without constraints3839// BAD:40Column(41children: [42Text('Header'),43ListView.builder( // ERROR: unbounded height44itemCount: 100,45itemBuilder: (_, i) => ListTile(title: Text('Item $i')),46),47],48)4950// FIX: Wrap ListView in Expanded51Column(52children: [53Text('Header'),54Expanded(55child: ListView.builder(56itemCount: 100,57itemBuilder: (_, i) => ListTile(title: Text('Item $i')),58),59),60],61)
1// ── BUG 3: Widget Not Visible ──2// Symptom: Widget exists but nothing shows on screen3// Common causes:45// a) Zero size: Container with no child and no explicit size6Container(color: Colors.blue) // invisible without size or child!7// FIX:8Container(color: Colors.blue, width: 100, height: 100)910// b) Covered by another widget: Stack ordering11Stack(12children: [13Container(color: Colors.blue, width: 200, height: 200),14Container(color: Colors.red, width: 200, height: 200), // covers blue15],16)1718// c) Transparent or same color as background19// Use Flutter Inspector to highlight widget bounds2021// ── BUG 4: Incorrect Alignment ──22// Symptom: Widget not positioned where expected23// Common cause: Missing Expanded in Row/Column with MainAxisAlignment2425// BAD: mainAxisAlignment has no effect when child fills all space26Row(27mainAxisAlignment: MainAxisAlignment.spaceBetween,28children: [29Expanded(child: Text('Left')), // Takes ALL space30Text('Right'),31],32)3334// FIX: Remove Expanded or use properly35Row(36mainAxisAlignment: MainAxisAlignment.spaceBetween,37children: [38Text('Left'),39Text('Right'), // Now spaceBetween works40],41)4243// ── BUG 5: Text Overflow ──44// Symptom: "A RenderFlex overflowed" due to long text4546// BAD:47Row(48children: [49Icon(Icons.person),50Text('This is a very long username that overflows the row'),51],52)5354// FIX: Wrap Text in Expanded or Flexible55Row(56children: [57Icon(Icons.person),58Expanded(59child: Text(60'This is a very long username that overflows the row',61overflow: TextOverflow.ellipsis,62),63),64],65)
1// ══════════════════════════════════2// DEBUGGING TOOLS FOR LAYOUT3// ══════════════════════════════════45// 1. Debug Paint: show widget boundaries6// In main():7import 'package:flutter/rendering.dart';8debugPaintSizeEnabled = true; // blue borders around every widget9debugPaintBaselinesEnabled = true; // show text baselines10debugPaintPointersEnabled = true; // show touch targets1112// 2. Widget Inspector (Flutter DevTools)13// Run: flutter run, then press 'w' in terminal14// Or: VS Code → Run → Open DevTools → Widget Inspector15// Features:16// - See the full widget tree17// - Highlight selected widget on device18// - View constraints, size, and padding19// - Toggle "Select Widget Mode" to tap and inspect2021// 3. LayoutBuilder: print constraints22LayoutBuilder(23builder: (context, constraints) {24debugPrint('Max width: ${constraints.maxWidth}');25debugPrint('Max height: ${constraints.maxHeight}');26return YourWidget();27},28)2930// 4. Container with debug border31Container(32decoration: BoxDecoration(33border: Border.all(color: Colors.red, width: 2),34),35child: suspiciousWidget,36)3738// 5. ColoredBox to visualize empty space39ColoredBox(40color: Colors.red.withOpacity(0.3),41child: suspiciousWidget,42)
When a layout looks wrong, wrap the suspicious widget in a Container with a red border to see its actual bounds. If the bounds are correct but the content looks wrong, the issue is inside the widget. If the bounds are unexpected, the issue is in the parent constraints. Work your way up the tree until you find where the layout breaks.
Most layout bugs are constraint mismatches between parent and child. Diagnose in this order:
This workflow avoids random property toggling and yields faster fixes.
Diagnose and fix common Flutter layout and rendering problems. Widgets are reusable UI blocks. You combine them like LEGO pieces to build screens.
Think in architecture, reliability, and team-level maintainability.
Sketch the widget tree first, then code from top to bottom.
Most Flutter productivity comes from understanding layout rules and composing widgets cleanly.
Good widget composition is architecture at UI level, because it decides testability and reuse.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
RenderFlex overflow happens when the total size of children in a Row or Column exceeds the available space. Fix with SingleChildScrollView, Expanded, Flexible, or by reducing content.
ListView tries to take infinite height. When placed in a Column (which also has unbounded height along the scroll axis), it causes a conflict. Expanded gives ListView a bounded height.
Setting debugPaintSizeEnabled to true draws colored borders around every widget, making it easy to see sizes, padding, and alignment issues directly on the screen.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue