当我按如下所示使用Expanded
小部件时,出现了一个错误,说 Incorrect use of ParentDataWidget。我在这里做错了什么?
还有,“所有权链”是什么意思?
代码如下,
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),
],
),
),
],
),
)
完整的错误如下,
======== 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.
1条答案
按热度按时间nxagd54h1#
您只能将
Expanded
用作Column
和Row
或Flex小工具的子项。扩展:一个小部件,用于扩展Row、Column或Flex的子项,以便子项填充可用空间。