Why This Happens
In Flutter, Expanded and Flexible are only valid inside Row, Column, or Flex widgets. Placing them in a Stack, Container, or other non-flex parent causes this error because only Flex widgets know how to distribute extra space.
The Problem
Container(
child: Expanded(
child: Text('Hello'), // Expanded inside Container!
),
)The Fix
Row(
children: [
Expanded(
child: Text('Hello'),
),
],
)Step-by-Step Fix
- 1
Identify the error
Look at the error message: Incorrect use of ParentDataWidget. Expanded must be inside a Flex widget.
- 2
Find the cause
Check if an Expanded or Flexible widget is placed inside a non-flex parent like Container, Stack, or Padding.
- 3
Apply the fix
Move the Expanded widget inside a Row, Column, or Flex, or remove it and use a different layout approach.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free