How to do yoyo animation in flutter?
You can listen to the status of an animation using 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();
}
});
The repeat
method supports the reverse
optional named argument, so you can write
animationController.repeat(reverse: true);
This is the modern, simple solution.