[英]How to restart an animation with flutter_animate?
I recently started using the package flutter_animate
and it was love at first sight.我最近开始使用 package
flutter_animate
,一见钟情。 But how do I restart an animation when a widget gets rebuilt?但是当一个小部件被重建时,我如何重新启动 animation?
Eg, my widget below animates great例如,我下面的小部件动画很棒
Text('Good\nJob!')
.animate()
.fadeOut(duration: 2000.ms).scaleXY(duration: 2000.ms, end: 2.0)
But when I setState
and the widget rebuilds, the animation doesn't restart and the text remains faded out.但是当我
setState
和小部件重建时,animation 不会重新启动并且文本仍然淡出。 Is there a way to trigger a restart on animations every time a widget rebuilds?有没有办法在每次重建小部件时触发动画重启?
You can use the AnimatedBuilder
widget provided by Flutter您可以使用 Flutter 提供的
AnimatedBuilder
widget
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return Text('Good\nJob!')
.animate()
.fadeOut(duration: 2000.ms).scaleXY(duration: 2000.ms, end: 2.0);
},
)
setState(() {
_animation.value = newValue;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.