본문 바로가기

Flutter

[j Flutter] Incorrect use of ParentDataWidget. 에러 해결법

728x90
반응형

flutter에서 해당 에러가 발생했다면,

======== Exception caught by widgets library =======================================================
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Positioned(top: 0.0, bottom: 0.0, width: 192.0) wants to apply ParentData of type StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.

Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically, Positioned widgets are placed directly inside Stack widgets.
The offending Positioned is currently placed inside a Transform widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  ColoredBox ← Container ← Positioned ← Transform ← Container ← AnimatedContainer ← Stack ← KeyedSubtree-[GlobalKey#8b22c] ← _BodyBuilder ← MediaQuery ← ⋯

 

 

before

Positioned(
  top: 0,
  bottom: 0,
  width: menuWidth,
  child: Container(
    color: Colors.yellow,
  ),
)​

 

after

Stack(
  children: [
    Positioned(
      top: 0,
      bottom: 0,
      width: menuWidth,
      child: Container(
        color: Colors.yellow,
      ),
    ),
  ],
)

 

 

positioned 위젯은 stack으로 감싸줘야한다.

728x90
반응형