Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter shows a red error screen saying RenderBox was not laid out

ErrorRenderBox was not laid out:

Short answer

RenderBox was not laid out is rarely the real error. It is usually a follow-up of an earlier one in the console, such as Vertical viewport was given unbounded height or an unbounded TextField width. Scroll up to the first error, then give that widget a bounded size with Expanded, Flexible or SizedBox.

  • Applies to Flutter 3.35, Dart 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Do not debug the RenderBox line. Run the app and read the console from the top: the first assertion that was thrown during layout is the one to fix.

    flutter run 2>&1 | head -n 60
  2. 2Match what you see, then jump to its fix

    1. 1Vertical viewport was given unbounded height.A ListView or GridView sits inside a ColumnFix
    2. 2An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.A TextField sits directly inside a RowFix

What does the error look like?

  • RenderBox was not laid out:
  • RenderViewport#5a477 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  • Vertical viewport was given unbounded height.
  • An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.

Cause 1 of 2

A ListView or GridView sits inside a Column

1Check

Look for a scrollable widget that is a direct child of a Column. A Column gives its children no height limit, and a scrollable tries to fill all the height it is offered.

grep -rn -B2 -A4 "Column(" lib/ | grep -n "ListView\|GridView"

2Fix

Give the scrollable a bounded height. Wrap it in Expanded to fill the space left in the Column. Use SizedBox for a fixed height or Flexible for a share of it.

Column(
  children: <Widget>[
    const Text('Header'),
    Expanded(
      child: ListView(
        children: const <Widget>[
          ListTile(title: Text('Map')),
        ],
      ),
    ),
  ],
)

3Verify

Hot reload. The red screen is gone and the list scrolls under the header.

flutter analyze

Confirmed by docs.flutter.dev

Did this fix it?

Cause 2 of 2

A TextField sits directly inside a Row

1Check

Find the TextField or TextFormField whose parent is a Row. A Row gives its children no width limit, and the text field has no width of its own.

grep -rn -B3 "TextField(\|TextFormField(" lib/ | grep "Row("

2Fix

Constrain the field with Expanded, or with a SizedBox of a fixed width.

Row(
  children: [
    Expanded(child: TextFormField()),
  ],
)

3Verify

Hot reload and type into the field. It now fills the free width of the row.

flutter run

Confirmed by docs.flutter.dev

Did this fix it?

How do I stop it coming back?

  • When a red screen appears, read the first error in the console, not the last one.
  • Before putting a ListView, GridView or TextField inside a Row or Column, decide where its size limit comes from.
  • Run the screen on a small phone size in the emulator to catch layout errors early.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.