Flutter RenderFlex Overflowed by Pixels: How to Fix It
A Row, Column, or other Flex-based widget renders content that doesn't fit within the space available to it, and Flutter shows a yellow-and-black striped overflow warning in debug mode.
A RenderFlex overflowed by 42 pixels on the right.
The Problem
A Row, Column, or other Flex-based widget renders content that doesn't fit within the space available to it, and Flutter shows a yellow-and-black striped overflow warning in debug mode.
Symptoms
- •Yellow/black diagonal-striped overflow indicator appears in the UI
- •Console prints 'A RenderFlex overflowed by X pixels on the [right/bottom]'
- •Layout looks fine on one screen size but overflows on smaller ones
Why This Happens
- •A Row's children collectively need more horizontal space than the Row has available
- •A Column's children need more vertical space than is available
- •Text with a long string and no wrapping/constraint applied
- •A widget given a fixed width/height that doesn't shrink for smaller screens
- •Missing Expanded/Flexible around a child that should share space instead of taking its natural size
// quick fix
Wrap the specific child that's too large in Expanded (if it should grow to fill space) or Flexible (if it should shrink but not necessarily fill), or wrap the whole Row/Column in a SingleChildScrollView if the content is meant to scroll.
The yellow-and-black stripes are Flutter's way of telling you, quite literally, "this content doesn't fit here." It's not a bug in Flutter's layout engine. It's Flutter accurately reporting that you asked for more space than exists, which is why the fix is almost always about the geometry of your layout rather than anything more exotic.
The most common mistake isn't picking the wrong fix, it's picking between Expanded and Flexible without understanding what each one actually does. Expanded forces its child to fill the remaining space, which is what you want for something like body text that should wrap. Flexible lets its child stay smaller than the available space, which is better for something like an icon or a button that shouldn't stretch just because there's room.
Testing only on one screen size is the other trap here. A layout that looks fine on your development device can overflow the moment someone opens it on a smaller phone or in split-screen mode, so it's worth actually resizing the window (or testing a couple of real device sizes) before calling a layout fix done.
How to Fix It
1. Use Expanded for children that should share available space
2. Use Flexible when the child should shrink but not fill
3. Wrap in SingleChildScrollView if the content is genuinely too big
4. Use Wrap instead of Row when items should flow to the next line
// common mistakes
- ×Wrapping in Expanded when Flexible was actually needed, causing over-stretching
- ×Fixing the overflow only on one screen size without testing smaller devices
- ×Using a fixed width/height instead of a relative constraint that adapts to screen size
How to Verify the Fix
- 1.Hot reload and confirm the yellow/black overflow stripes are gone
- 2.Resize the app window or test on a smaller device/emulator to confirm the layout holds at smaller widths
- 3.Check that text truncates or wraps as intended rather than being clipped unexpectedly
Related Problems
Skip the boilerplate
Production-ready Flutter starter kit with Firebase Auth, Firestore, Cloud Functions, push notifications, and Clean Architecture — ship your app in days, not months.
Did this article save you time?
I write these for free. If it helped, a coffee keeps me going — and more articles coming.