Flare Actor无法在“定位的小部件”内部甚至在flutter的列或行中工作

时间:2019-06-09 22:26:57

标签: flutter flutter-layout flare

               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 named参数上方有一个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.  

3 个答案:

答案 0 :(得分:1)

这是因为尺寸问题...

仔细阅读以下错误

I / flutter(18558):RenderStack对象在布局期间被赋予了无限大小。

I / flutter(18558):这可能意味着它是一个渲染对象, 试图做得尽可能大,但它被放 在另一个允许它 孩子们可以自己选择尺寸。

专注于这些行,您将了解问题

但是它被放了 在另一个允许它 孩子们可以自己选择尺寸。

应用以下附加内容:

  • 在“位置”小部件中添加位置偏移。
  • 将SizedBox的大小增加到(360.0,560.0)。
  • 用Container()替换Sizedbox()。
  • 重命名耀斑文件并重新导入。
  • 在FlareActor()中添加fit属性。
  • 为Flareactor()使用适当的父窗口小部件,该窗口小部件不会限制子项的大小。

答案 1 :(得分:1)

您实际上可以将其放在Expanded()中并具有例如一个容器作为孩子。例如。效果很好:

body: Column(
          children: [
            Expanded(
              child: Container(
                child: FlareActor(

这样,您可以将多个照明弹放在一列中。有一个很好的文档。只需在此处向下滚动到示例25:https://flutter.dev/docs/development/ui/layout/constraints

答案 2 :(得分:-1)

用Expanded()包装FlareActor: 示例:

Expanded(child: FlareActor("Assets/wellness.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"idle")),