Widget Inspector: constraints, padding, and overflow debugging
3 min read
DevTools
Theory — why the Inspector matters
Most overflow, clipping, and alignment bugs come from misunderstanding constraints, not Flutter being weird. Flutter's golden rule is "constraints go down, sizes go up." Most layout failures happen when you violate it:
| Symptom | Usual cause |
|---|---|
| "RIGHT OVERFLOWED BY X PIXELS" | Child wants more main-axis space than parent allows |
| Text disappears / clips | Unbounded width with no Expanded/Flexible |
| Children stack instead of laying out | Wrong widget (Stack vs Column) or unbounded constraints |
| Layout looks fine on phone, broken on tablet | Hard-coded sizes instead of flex / constraints |
| RenderBox was not laid out | A widget hit intrinsic* calls in an unsupported parent |
The Inspector shows you the actual constraints each widget received — usually the diff between what you think and what's happening.
Practical workflow
flutter runyour app, open DevTools → Inspector.- Click "Select Widget Mode" (the cross-hair icon).
- Tap the misbehaving area in your app.
- Read the right-hand panel:
- Constraints:
BoxConstraints(0.0<=w<=…, 0.0<=h<=…)— what the parent gave the widget. - Size: what the widget chose.
- Properties: padding, margin, alignment, flex, etc.
- Constraints:
- Walk up the tree until you find the parent enforcing the wrong constraints.
Useful debug flags
import 'package:flutter/rendering.dart';
void main() {
debugPaintSizeEnabled = true; // outlines every box (great for spotting padding)
debugRepaintRainbowEnabled = true; // each repaint cycles colours — flickering = too many repaints
debugPaintLayerBordersEnabled = true; // visualises layer boundaries
runApp(const MyApp());
}
In the Inspector itself: toggle "Show Layout Guidelines" to overlay box edges; "Highlight Repaints" is the GUI equivalent of debugRepaintRainbowEnabled.
What to look for first
| Check | Why |
|---|---|
Row/Column with long Text and no Expanded / Flexible | Most common overflow source |
Nested Container(padding: ...) stacks | Each layer trims the available width |
| Widgets relying on fixed pixel widths | Will break on narrow / wide devices |
ListView inside Column without Expanded | Unbounded height — won't render |
Expanded / Flexible inside a SingleChildScrollView | Unbounded main axis — they error |
Common mistakes to avoid
// ❌ Reading layout from the source instead of the inspector
// You'll spend an hour debating Padding vs Margin while DevTools would show it in 3 clicks.
// ❌ Hiding errors with overflow: clip
ClipRect(child: SomeOverflowingWidget()); // hides the bug, doesn't fix it
// ✅ Use Inspector to find which constraint is wrong, then fix it
// ❌ Disabling overflow assertions in release mode and shipping
// Overflow indicators only appear in debug — the layout is still broken at runtime
// ❌ Believing "Flutter is weird"
// 99% of the time, the parent's constraints are exactly what they say they are
Interview follow-ups
-
What does the "RIGHT OVERFLOWED BY 24 PIXELS" warning actually mean? A child requested more main-axis space than its parent (typically a
Row) allows. The parent'smaxWidthwas less than what the child wanted to be. Fix by giving the child anExpanded/Flexible, or by reducing its content (e.g.,Text(... overflow: TextOverflow.ellipsis)). -
How do you debug "RenderBox was not laid out"? It usually means the widget tried to read a child's size before layout completed — e.g., using a scroll-direction-flexible child inside an unbounded parent. The Inspector's stack and the error message point to the offending RenderObject.
-
What is
debugPaintSizeEnabledand when do you turn it on? It overlays a thin outline around every RenderBox, plus padding visualisation. Turn it on when you're not sure where one widget ends and another begins — invaluable for diagnosing alignment and padding issues. -
What does the rainbow repaint overlay tell you? Each repaint changes the colour overlaid on a region. If a small area is constantly cycling colours, that subtree is repainting unnecessarily — often a sign you need a
RepaintBoundaryor thatsetStateis being called at too high a level.
How helpful was this content?
Please sign in to rate this article.