Flutter prints this in debug mode. The message changes with the widget, but it always names the offending widget and where it’s placed:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget.
Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a Padding widget.
The last line is the fix: here an Expanded sits inside a Padding instead of directly inside the Column.
Why it happens
Some widgets don’t draw anything. They pass layout instructions to their parent:
| Widget | Must be a direct child of | Tells the parent |
|---|---|---|
Expanded, Flexible, Spacer |
Row, Column, Flex |
how much of the free space to take |
Positioned, Positioned.fill, PositionedDirectional |
Stack |
where to place the child |
LayoutId |
CustomMultiChildLayout |
which child is which |
TableCell |
TableRow in a Table |
vertical alignment in the cell |
If any other widget sits in between, even a harmless Padding, the instruction lands on the wrong parent and Flutter reports it.
Fix 1: move the wrapper inside
Wrong:
Column(
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Expanded(child: ListView(...)), // Expanded is not a direct child of Column
),
],
)
Right:
Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(16),
child: ListView(children: const [Text('Feed')]),
),
),
],
)
Positioned follows the same rule. It goes directly in the Stack, with the Container inside it:
Stack(
children: [
const Positioned.fill(child: ColoredBox(color: Colors.black12)),
Positioned(
top: 8,
right: 8,
child: Container(
padding: const EdgeInsets.all(4),
color: Colors.red,
child: const Text('NEW'),
),
),
],
)
Fix 2: the hidden case, a custom widget that returns Expanded
This one is harder to spot, because the code looks right:
class PriceLabel extends StatelessWidget {
@override
Widget build(BuildContext context) => Expanded(child: Text(price)); // risky
}
PriceLabel only works when its parent is a Row or Column. Put it in a Padding, a ListView or a Wrap, and you get the error. Return the plain content from your widget and let the caller decide: Row(children: [Expanded(child: PriceLabel())]). Or make the widget return its own Row, as in this tested example:
class BottomBar extends StatelessWidget {
const BottomBar({super.key});
@override
Widget build(BuildContext context) {
return Row(
children: [
const Expanded(child: Text('Total: AED 120')),
const Spacer(),
FilledButton(onPressed: () {}, child: const Text('Pay')),
],
);
}
}
Fix 3: Expanded in a ListView, Wrap or Stack
These parents don’t divide space the way Row and Column do, so Expanded and Spacer mean nothing there:
- In a ListView, give the child a height with
SizedBox, or restructure with slivers. See vertical viewport was given unbounded height. - In a Wrap, remove
Expanded; items size themselves and wrap to the next line. - In a Stack, use
Positioned.fillinstead ofExpanded.
Does it matter in release builds?
The check only runs in debug mode, so release builds don’t show the error. But the layout instruction is still ignored or applied wrongly, which can show up as squashed or invisible widgets on some screens. Fix it while you can still see the message.
Frequently asked questions
What does "Incorrect use of ParentDataWidget" mean?
A widget that gives instructions to its parent, such as Expanded, Flexible, Spacer or Positioned, is not a direct child of the parent it works with. Expanded needs a Row, Column or Flex; Positioned needs a Stack. The error message says which widget it is currently inside.
Can I put Expanded inside a Container or Padding?
No. Expanded must be the direct child of the Row or Column. Put the Container or Padding inside the Expanded instead: Expanded(child: Padding(…)).
Why does my custom widget cause this error?
Its build method probably returns Expanded, Flexible or Positioned. That only works if every caller places it directly in a Row, Column or Stack. Return the content without the Expanded and let the parent wrap it.
Can I use Expanded inside a ListView?
No. A ListView gives its children unlimited height in the scroll direction, so there is no space to expand into. Give the child a fixed height with SizedBox, or use a Column inside an Expanded if the screen should not scroll.
Stuck on a build or a store release? I fix and maintain Flutter apps, or tell me about your project. More fixes: all Flutter answers.