Flutter TextField inside a Row throws an unbounded width layout error
An 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.
Fix it fast
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 -v2Match what you see, then jump to its fix
- 1
The first error says the InputDecorator cannot have an unbounded width and mentions a RowA TextField or TextFormField sits directly in a RowFix - 2
RenderBox 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
Vertical viewport was given unbounded heightA scrollable list placed in a Column has unbounded heightFix
- 1
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.dart2Fix
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 runConfirmed by docs.flutter.dev
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 runConfirmed by docs.flutter.dev
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 ListView2Fix
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 runConfirmed by docs.flutter.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix