FX03: Incorrect ParentDataWidget Placement
Inspect widget tree relationships and ensure ParentData widgets are direct descendants
Observed Symptom & Flutter Error Assertion
Incorrect use of ParentDataWidget: Positioned widgets must be placed directly inside Stack widgets, or Expanded directly inside Flex/Row/Column.
════╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during widget build:
Incorrect use of ParentDataWidget.
The following ParentDataWidgets are providing parent data to the same RenderObject:
- Positioned(top: 10.0, left: 10.0)
However, the ParentDataWidget was not a direct child of a Stack widget.
The parent of Positioned was:
Container
The nearest ancestor Stack was:
Stack
════════════════════════════════════════════════════════════════════════════════════════════════════Declared Conditions
Nesting an intermediary widget (e.g. Container, Padding, or GestureDetector) between a ParentDataWidget (Positioned, Expanded, Flexible) and its required parent (Stack, Row, Column).
Official References
ParentDataWidget subclasses (like Positioned or Expanded) exist specifically to write layout parameters (StackParentData, FlexParentData) onto the RenderObject of their immediate parent. An intermediary widget intercepts this chain and cannot accept the foreign ParentData.
Move the ParentDataWidget so it is an immediate child of its parent (e.g. Stack > Positioned > Container, never Stack > Container > Positioned).
ParentDataWidget Tree Architecture: Broken vs Valid
Flutter RenderObject ParentData Attachment RuleParentDataWidget cannot attach StackParentData or FlexParentData onto an intermediary Container's RenderObject.
ParentDataWidget immediately communicates with parent's RenderObject, writing offsets and flex factors cleanly.
Positioned must be a direct child of Stack to write StackParentData onto the RenderStack.
Corrected: Positioned as Direct Child of Stack
Move Positioned directly below Stack, then place the Container or Badge inside Positioned.
- ✓Place Positioned as a direct child of Stack
- ✓Move decorative styling and padding inside Positioned's child
import 'package:flutter/material.dart';
void main() => runApp(const FixedParentDataDemo());
class FixedParentDataDemo extends StatelessWidget {
const FixedParentDataDemo({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Fixed: Direct Positioned Child'), backgroundColor: const Color(0xFF0D9488)),
body: Center(
child: SizedBox(
width: 320,
height: 200,
child: Stack(
children: [
Container(
width: 320,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: const Color(0xFF2DD4BF), width: 2),
),
child: const Center(
child: Text('Card Surface Area', style: TextStyle(fontWeight: FontWeight.bold)),
),
),
// FIX: Positioned is a direct child of Stack!
Positioned(
top: 14,
right: 14,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFF2DD4BF),
borderRadius: BorderRadius.circular(8),
),
child: const Text('PRO', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12)),
),
),
],
),
),
),
),
);
}
}