Dart flatter:AnimatedContainer-childrenwidgets';属性未设置动画

Dart flatter:AnimatedContainer-childrenwidgets';属性未设置动画,dart,flutter,flutter-animation,Dart,Flutter,Flutter Animation,我有一个简单的AnimatedWidget和一个子widget AnimatedContainer( duration: Duration(milliseconds: 2000), curve: Curves.bounceOut, decoration: BoxDecoration( color: Colors.purple, ), child: FlutterLogo( size: _boxSize, ), ), 其中,\u boxS

我有一个简单的
AnimatedWidget
和一个子widget

AnimatedContainer(
   duration: Duration(milliseconds: 2000),
   curve: Curves.bounceOut,
   decoration: BoxDecoration(
      color: Colors.purple,
   ),
   child: FlutterLogo(
     size: _boxSize,
   ),
),
其中,
\u boxSize
的动画如下:

void _startAnimation() => setState(() {
    _boxSize *= 1.7;
  });
AnimatedContainer
不适用于子部件。您需要更改
AnimatedContainer
的直接属性,动画才能工作

这符合文件规定:

The [AnimatedContainer] will automatically animate between the old 
and new values of properties when they change using the provided curve 
and duration. Properties that are null are not animated. 
Its child and descendants are not animated.

AnimatedContainer
等价的是什么,它还能够为其子对象设置动画?

没有一个神奇的小部件可以简单地递归地为所有子对象设置动画。但我认为你想要的是一个隐式动画小部件。你改变一个小部件的构造器参数,当它改变时,它会从一个值变成下一个值

最简单的方法可能是带有
AnimatedWidgetBaseState
隐式iMatedWidget
。因此,对于要为
boxSize
属性设置动画的示例,这可能如下所示:

类animatedFlatterLogo隐式扩展了animatedWidget{
const animatedflatterlogo({Key Key,@required this.boxSize,@required Duration})
:super(键:键,持续时间:持续时间);
最终双箱尺寸;
@凌驾
隐式YanImagedWidgetState createState()=>_animatedFlatterLogoState();
}
类_animatedFlatterLogoState扩展AnimatedWidgetBaseState{
吐温箱尺寸;
@凌驾
无效预告(访客){
_boxSize=visitor(_-boxSize,widget.boxSize,(动态值)=>Tween(开始:值));
}
@凌驾
小部件构建(构建上下文){
返回容器(
孩子:我的标志(
大小:_boxSize?.evaluate(动画),
),
);
}
}

这已经相当简洁了,唯一真正的样板基本上是
forEachTween(visitor)
方法,它必须为所有要设置动画的属性创建
Tween
对象。

很少有小部件可以设置孩子的动画。您可以使用
AnimatedSwitcher
widget以首选大小交换新的flatter徽标widget

  • -此小部件将用新小部件交换子小部件
  • -只要给定位置发生变化,它就会从堆栈小部件中更改子对象的位置
  • -align的动画版本,该版本将在给定对齐方式更改时更改子对象的对齐方式
  • -它会在两个孩子之间淡入淡出,并在他们的大小之间设置动画

  • 你找到解决办法了吗?