Widget Inspector: constraints, padding, and overflow debugging

Low PriorityAsked in ~40% of Flutter interviews

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:

SymptomUsual cause
"RIGHT OVERFLOWED BY X PIXELS"Child wants more main-axis space than parent allows
Text disappears / clipsUnbounded width with no Expanded/Flexible
Children stack instead of laying outWrong widget (Stack vs Column) or unbounded constraints
Layout looks fine on phone, broken on tabletHard-coded sizes instead of flex / constraints
RenderBox was not laid outA 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

  1. flutter run your app, open DevTools → Inspector.
  2. Click "Select Widget Mode" (the cross-hair icon).
  3. Tap the misbehaving area in your app.
  4. 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.
  5. 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

CheckWhy
Row/Column with long Text and no Expanded / FlexibleMost common overflow source
Nested Container(padding: ...) stacksEach layer trims the available width
Widgets relying on fixed pixel widthsWill break on narrow / wide devices
ListView inside Column without ExpandedUnbounded height — won't render
Expanded / Flexible inside a SingleChildScrollViewUnbounded 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

  1. 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's maxWidth was less than what the child wanted to be. Fix by giving the child an Expanded/Flexible, or by reducing its content (e.g., Text(... overflow: TextOverflow.ellipsis)).

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

  3. What is debugPaintSizeEnabled and 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.

  4. 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 RepaintBoundary or that setState is being called at too high a level.


How helpful was this content?

Please sign in to rate this article.