Maaz Zindani

Loading the index…

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

Flutter TextField inside a Row throws an unbounded width layout error

ErrorAn InputDecorator, which is typically created by a TextField, cannot have an unbounded width.

Short answer

A Row gives its children unlimited width, and a TextField cannot size itself inside unlimited width. Flutter then throws an InputDecorator error and often a second RenderBox not laid out error. Wrap the TextField in Expanded to fill the free space, or in a SizedBox with a fixed width.

  • Applies to Flutter 3.x, Dart 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Scroll up in the debug console to the first assertion, not the last one. RenderBox was not laid out is usually only a side effect of the real error above it.

    flutter run -v
  2. 2Match what you see, then jump to its fix

    1. 1The first error says the InputDecorator cannot have an unbounded width and mentions a RowA TextField or TextFormField sits directly in a RowFix
    2. 2RenderBox was not laid out with a viewport or render object marked NEEDS-LAYOUTOnly RenderBox was not laid out is visible, so the real error is missedFix
    3. 3Vertical viewport was given unbounded heightA scrollable list placed in a Column has unbounded heightFix

What does the error look like?

  • An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.
  • RenderBox was not laid out

Cause 1 of 3

A TextField or TextFormField sits directly in a Row

1Check

Find the Row in the widget that the error points to. If the text field is a direct child with no width constraint, this is the cause.

grep -n "Row(" -A4 lib/screens/login_screen.dart

2Fix

Wrap the field in Expanded so it takes the space left over by the other children. When you want an exact width instead, use SizedBox.

Row(
  children: [
    Expanded(child: TextFormField()),
    const SizedBox(width: 8),
    const Icon(Icons.search),
  ],
)

// fixed width instead:
Row(children: [SizedBox(width: 200, child: TextField())])

3Verify

Hot restart the app; the field shows and no assertion is printed.

flutter run

Confirmed by docs.flutter.dev

Did this fix it?

Cause 2 of 3

Only RenderBox was not laid out is visible, so the real error is missed

1Check

The Flutter guide says this error is often a side effect of an earlier problem in the rendering pipeline, usually a violation of box constraints. It lists the unbounded-width InputDecorator error as one of the two usual primary errors.

flutter run 2>&1 | grep -n "unbounded\|not laid out"

2Fix

Fix the primary error above it, the unbounded width or height, by giving the widget a constraint. Expanded, Flexible and SizedBox are the tools the guide names.

// unbounded width in a Row
Row(children: [Expanded(child: TextField())])

3Verify

Run again; neither message appears.

flutter run

Confirmed by docs.flutter.dev

Did this fix it?

Cause 3 of 3

A scrollable list placed in a Column has unbounded height

1Check

This is the vertical twin of the same problem: a ListView or GridView inside a Column. The Column does not limit its children's height, and the list tries to take all the space.

grep -n "Column(" -A6 lib/screens/*.dart | grep -n ListView

2Fix

Wrap the list in Expanded to fill the remaining space, or give it a height with SizedBox or Flexible.

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

3Verify

Hot restart; the list scrolls inside the remaining space.

flutter run

Confirmed by docs.flutter.dev

Did this fix it?

How do I stop it coming back?

  • Reach for Expanded the moment a text field, list or other greedy widget goes into a Row or Column.
  • Read the first error in the console, not the last.
  • Prefer SizedBox with an explicit width when a field must keep a fixed size.

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.