Search code examples
flutterflutter-layoutflutter-animation

How to repeat an animation certain number of time?


I have an AnimationController object and I want to repeat an animation 10 times.

AnimationController controller = ...;
controller.repeat(count: 10); // Wish there was something like this

Note: I'm not looking for workarounds, like calling controller.forward(from: 0) 10 times recursively or Timer.periodic, or keeping a count of AnimationController.animationStatus, etc and then stopping the animation.


Solution

  • Thanks to @pskink.

    You need to use SawTooth curve and set the count. For example:

    FadeTransition(
      opacity: CurvedAnimation(parent: _controller, curve: SawTooth(10)), 
      child: SomeChild(),
    );