An error occurred saying Incorrect use of ParentDataWidget when I used the Expanded
widget as follows.
What did I do wrong here?
As well, what is the meaning of ownership chain?
The code is as follows,
Expanded(
child: Wrap(
alignment: WrapAlignment.spaceAround,
children: <Widget>[
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
verticalDirection: VerticalDirection.down,
children: <Widget>[
Text(
"${Constants.ASSIGNMENT_PREFIX} ${assignment?.id}",
style: Theme.of(context)
.textTheme
.headline6),
_getAssignState(
assignment?.status),
],
),
),
],
),
)
The full error is as follows,
======== Exception caught by widgets library =======================================================
The following assertion was thrown while applying parent data.:
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 WrapParentData.
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 Wrap widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Row ← Expanded ← Wrap ← Expanded ← Row ← Padding ← Padding ← DecoratedBox ← Container ← Listener ← ⋯
When the exception was thrown, this was the stack:
#0 RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:5723:11)
#1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5739:6)
#2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5761:7)
#3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5440:5)
#4 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6228:11)
...
====================================================================================================
Reloaded 1 of 2005 libraries in 1,286ms.
You can only use Expanded
as a child of Column
and Row
or the Flex widget.
Expanded: A widget that expands a child of a Row, Column, or Flex so that the child fills the available space.
child: Wrap(
alignment: WrapAlignment.spaceAround,
children: <Widget>[
// Expanded( => remove this
Row()