Skip to main content
Back to Fix Lab Hub
Verified: Flutter 3.24.3 • Dart 3.5.3

FX03: Incorrect ParentDataWidget Placement

Inspect widget tree relationships and ensure ParentData widgets are direct descendants

APIs:StackPositionedExpandedFlexibleParentDataWidget

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).

Root Cause Analysis

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.

Verified Correction Rule

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 Rule
❌ Invalid Tree (Intermediary Interception)
Stack / Row (Expects target ParentData)
└── Container / Padding (Intermediary BoxParentData)
└── Positioned / Expanded (ASSERTION CRASH)

ParentDataWidget cannot attach StackParentData or FlexParentData onto an intermediary Container's RenderObject.

✅ Valid Tree (Direct Descendant)
Stack / Row (Supplies target ParentData slot)
└── Positioned / Expanded (Direct Child)
└── Container / Padding (Child content)

ParentDataWidget immediately communicates with parent's RenderObject, writing offsets and flex factors cleanly.

Evidence Mode: Live Flutter Engine
Width:
Correction Strategy:

Positioned must be a direct child of Stack to write StackParentData onto the RenderStack.

Real Flutter Web CanvasKit Engine320pxlight

Corrected: Positioned as Direct Child of Stack

Move Positioned directly below Stack, then place the Container or Badge inside Positioned.

Open in Studio
Key Architectural Modifications:
  • Place Positioned as a direct child of Stack
  • Move decorative styling and padding inside Positioned's child
standalone_fx03_fixed_320px.dartFlutter 3.24.3 • Zero External Dependencies • Runnable
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)),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}