Introduction
The RenderFlex overflowed error is one of the most common Flutter layout errors. It appears as a yellow-and-black striped warning banner at the edge of the overflow, with console output showing exactly how many pixels overflowed. This happens when children of a Column or Row require more space than is available, typically on smaller devices like iPhone SE or older Android phones.
Symptoms
- Yellow and black striped bars at the edge of the screen
- Console error:
`- A RenderFlex overflowed by 42 pixels on the bottom.
`- Or:
`- A RenderFlex overflowed by 120 pixels on the right.
`- Layout looks correct on larger devices but breaks on smaller screens
- Error shows in debug mode with full diagnostic tree
Common Causes
- Fixed-size widgets inside a
Columnthat exceed screen height Rowwith children wider than the screen- Not using
ExpandedorFlexiblefor widgets that should shrink - Hardcoded dimensions that do not account for safe areas
- ListView inside a Column without proper constraints
Step-by-Step Fix
- 1.Wrap overflowing Column in SingleChildScrollView:
- 2.```dart
- 3.// WRONG - Column can overflow the screen
- 4.Column(
- 5.children: [
- 6.const Text('Header'),
- 7.ListView.builder(
- 8.itemCount: 20,
- 9.itemBuilder: (context, index) => ListTile(title: Text('Item $index')),
- 10.),
- 11.],
- 12.)
// CORRECT - wrap in SingleChildScrollView SingleChildScrollView( child: Column( children: [ const Text('Header'), ...List.generate(20, (index) => ListTile(title: Text('Item $index'))), ], ), ) ```
- 1.Use Expanded for widgets that should fill remaining space:
- 2.```dart
- 3.// WRONG - both Text widgets want their intrinsic width
- 4.Row(
- 5.children: [
- 6.Text('This is a very long description that will overflow'),
- 7.Text('Short'),
- 8.],
- 9.)
// CORRECT - use Expanded to constrain width Row( children: [ Expanded( child: Text( 'This is a very long description that will wrap correctly', softWrap: true, ), ), Text('Short'), ], ) ```
- 1.Use Flexible when widgets should shrink but not force-fill:
- 2.```dart
- 3.Row(
- 4.children: [
- 5.Flexible(
- 6.flex: 2,
- 7.child: Container(color: Colors.blue, height: 50),
- 8.),
- 9.Flexible(
- 10.flex: 1,
- 11.child: Container(color: Colors.red, height: 50),
- 12.),
- 13.],
- 14.)
- 15.
` - 16.Account for safe areas and system UI:
- 17.```dart
- 18.SafeArea(
- 19.child: SingleChildScrollView(
- 20.padding: const EdgeInsets.all(16.0),
- 21.child: Column(
- 22.crossAxisAlignment: CrossAxisAlignment.stretch,
- 23.children: [
- 24.// Your content here - safe from notches, status bars, etc.
- 25.],
- 26.),
- 27.),
- 28.)
- 29.
` - 30.Use LayoutBuilder for responsive layouts:
- 31.```dart
- 32.LayoutBuilder(
- 33.builder: (context, constraints) {
- 34.if (constraints.maxWidth < 600) {
- 35.return Column(children: _buildVerticalLayout());
- 36.} else {
- 37.return Row(children: _buildHorizontalLayout());
- 38.}
- 39.},
- 40.)
- 41.
` - 42.Use OverflowBar for automatic overflow handling:
- 43.```dart
- 44.OverflowBar(
- 45.spacing: 8,
- 46.children: [
- 47.ElevatedButton(onPressed: () {}, child: const Text('Action 1')),
- 48.ElevatedButton(onPressed: () {}, child: const Text('Action 2')),
- 49.ElevatedButton(onPressed: () {}, child: const Text('Action 3')),
- 50.],
- 51.)
- 52.
`
Prevention
- Always wrap scrollable content in
SingleChildScrollView - Use
ExpandedandFlexibleinstead of fixed sizes - Test on small devices (iPhone SE, small Android phones) in development
- Use
debugPaintSizeEnabled = trueto visualize layout boundaries - Use
MediaQueryorLayoutBuilderfor responsive design - Enable
debugOverflowAllowed = truein debug mode to catch overflow early