简体   繁体   English

如何在flutter中做yoyo动画?

[英]How to do yoyo animation in flutter?

I know there is repeat() method on AnimationController but it always starts from the start.我知道AnimationController上有repeat()方法,但它总是从头开始。

Is there a built-in way to do one forward and one reverse animation, and to repeat that?有没有内置的方法来做一个正向和一个反向动画,并重复它?

Thank you谢谢

The repeat method supports the reverse optional named argument, so you can write repeat方法支持reverse可选命名参数,因此您可以编写

animationController.repeat(reverse: true);

This is the modern, simple solution.这是现代简单的解决方案。

You can listen to the status of an animation using addStatusListener .您可以使用addStatusListener动画的状态。 And on animation end reverse it.并在动画结束时反转它。

final AnimationController c;
...
c.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
    c.reverse();
  }
  else if (status == AnimationStatus.dismissed) {
    c.forward();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM