Flare Actor 无法在 Positioned Widget 内工作,甚至无法在 Column 或 Row 中工作
Flare Actor is not working inside Positioned Widget or even in Column or in Row in flutter
children: [
Positioned(
top: 1,
child: SizedBox(
height: 300,
width: 300,
child: FlareActor(
'assets/New File 5 (2).flr',
alignment: Alignment.centerRight,
isPaused: true,
animation: 'Checkmark Appear',
),
),
),
Children 命名参数上方有一个 Stack Widget 名称。当我尝试 运行 列、行或列表小部件中的 Flare Actor 小部件时,它不起作用并且消失了。但是当我在 Stack 中使用它时它工作得很好但我无法正确定位它。当我检查我的调试控制台时,出现了一个错误,就是这样:
The following assertion was thrown during performLayout():
I/flutter (18558): RenderStack object was given an infinite size during layout.
I/flutter (18558): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (18558): inside another render object that allows its children to pick their own size.
I/flutter (18558): The nearest ancestor providing an unbounded width constraint is:
I/flutter (18558): RenderStack#2151d relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (18558): creator: Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter (18558): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#874dd ink
renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter (18558): AnimatedPhysicalModel ← Material ← ⋯
I/flutter (18558): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter (18558): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=560.0) size: Size(360.0, 560.0)
I/flutter (18558): alignment: AlignmentDirectional.topStart
I/flutter (18558): textDirection: ltr
I/flutter (18558): fit: loose
I/flutter (18558): overflow: clip
I/flutter (18558): The nearest ancestor providing an unbounded height constraint is:
I/flutter (18558): RenderStack#2151d relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (18558): creator: Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter (18558): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#874dd ink
I/flutter (18558): renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter (18558): AnimatedPhysicalModel ← Material ← ⋯
I/flutter (18558): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter (18558): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=560.0)
I/flutter (18558): size: Size(360.0, 560.0)
I/flutter (18558): alignment: AlignmentDirectional.topStart
I/flutter (18558): textDirection: ltr
I/flutter (18558): fit: loose
I/flutter (18558): overflow: clip
I/flutter (18558): The constraints that applied to the RenderStack were:
I/flutter (18558): BoxConstraints(unconstrained)
I/flutter (18558): The exact size it was given was:
I/flutter (18558): Size(Infinity, Infinity)
I/flutter (18558): See https://flutter.dev/layout/ for more information.
用 Expanded() 包装 FlareActor:
示例:
Expanded(child: FlareActor("Assets/wellness.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"idle")),
这是因为尺寸问题...
仔细阅读以下错误
I/flutter (18558): RenderStack object was given an infinite size during layout.
I/flutter (18558): This probably means that it is a render object that
tries to be as big as possible, but it was put
inside another render object that allows its
children to pick their own size.
关注这几行,问题就明白了
but it was put
inside another render object that allows its
children to pick their own size.
应用以下补充:
- 在定位小部件中添加位置偏移量。
- 将 SizedBox 的大小增加到 (360.0, 560.0)。
- 用 Container() 替换 Sizedbox()。
- 重命名您的 flare 文件并重新导入。
- 在 FlareActor() 中添加一个拟合 属性。
- 为不限制子大小的 Flareactor() 使用适当的父小部件。
您实际上可以将其放入 Expanded() 中,例如一个 Container 作为 child。例如。这工作得很好:
body: Column(
children: [
Expanded(
child: Container(
child: FlareActor(
这样,您就可以在一列中放置多个照明弹。有一个很棒的文档。只需向下滚动到此处的示例 25:https://flutter.dev/docs/development/ui/layout/constraints
children: [
Positioned(
top: 1,
child: SizedBox(
height: 300,
width: 300,
child: FlareActor(
'assets/New File 5 (2).flr',
alignment: Alignment.centerRight,
isPaused: true,
animation: 'Checkmark Appear',
),
),
),
Children 命名参数上方有一个 Stack Widget 名称。当我尝试 运行 列、行或列表小部件中的 Flare Actor 小部件时,它不起作用并且消失了。但是当我在 Stack 中使用它时它工作得很好但我无法正确定位它。当我检查我的调试控制台时,出现了一个错误,就是这样:
The following assertion was thrown during performLayout():
I/flutter (18558): RenderStack object was given an infinite size during layout.
I/flutter (18558): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (18558): inside another render object that allows its children to pick their own size.
I/flutter (18558): The nearest ancestor providing an unbounded width constraint is:
I/flutter (18558): RenderStack#2151d relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (18558): creator: Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter (18558): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#874dd ink
renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter (18558): AnimatedPhysicalModel ← Material ← ⋯
I/flutter (18558): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter (18558): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=560.0) size: Size(360.0, 560.0)
I/flutter (18558): alignment: AlignmentDirectional.topStart
I/flutter (18558): textDirection: ltr
I/flutter (18558): fit: loose
I/flutter (18558): overflow: clip
I/flutter (18558): The nearest ancestor providing an unbounded height constraint is:
I/flutter (18558): RenderStack#2151d relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (18558): creator: Stack ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter (18558): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#874dd ink
I/flutter (18558): renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter (18558): AnimatedPhysicalModel ← Material ← ⋯
I/flutter (18558): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter (18558): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=560.0)
I/flutter (18558): size: Size(360.0, 560.0)
I/flutter (18558): alignment: AlignmentDirectional.topStart
I/flutter (18558): textDirection: ltr
I/flutter (18558): fit: loose
I/flutter (18558): overflow: clip
I/flutter (18558): The constraints that applied to the RenderStack were:
I/flutter (18558): BoxConstraints(unconstrained)
I/flutter (18558): The exact size it was given was:
I/flutter (18558): Size(Infinity, Infinity)
I/flutter (18558): See https://flutter.dev/layout/ for more information.
用 Expanded() 包装 FlareActor: 示例:
Expanded(child: FlareActor("Assets/wellness.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"idle")),
这是因为尺寸问题...
仔细阅读以下错误
I/flutter (18558): RenderStack object was given an infinite size during layout.
I/flutter (18558): This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
关注这几行,问题就明白了
but it was put inside another render object that allows its children to pick their own size.
应用以下补充:
- 在定位小部件中添加位置偏移量。
- 将 SizedBox 的大小增加到 (360.0, 560.0)。
- 用 Container() 替换 Sizedbox()。
- 重命名您的 flare 文件并重新导入。
- 在 FlareActor() 中添加一个拟合 属性。
- 为不限制子大小的 Flareactor() 使用适当的父小部件。
您实际上可以将其放入 Expanded() 中,例如一个 Container 作为 child。例如。这工作得很好:
body: Column(
children: [
Expanded(
child: Container(
child: FlareActor(
这样,您就可以在一列中放置多个照明弹。有一个很棒的文档。只需向下滚动到此处的示例 25:https://flutter.dev/docs/development/ui/layout/constraints