Flutter: How to terminate animation loop after x cycles?

You are using a repeating AnimationController with a duration of 2 seconds. You started the animation with a loop: _controller.repeat(reverse: true). To stop it, you can call _controller.stop() or _controller.reset(). The only problem is, when to do it.

There are a couple of different approaches. The most obvious one is to use a Timer (or Future.delayed) to schedule a callback a few seconds later. For example, your animation runs for 2 seconds and reverses for another 2 seconds, that's 4 seconds in total. To stop after 10 repeats, is the same as saying "stop after 40 seconds", so you can write:

Future.delayed(Duration(seconds: 40), () {
  _controller.stop();
});

Alternatively, you can use addStatusListener to monitor your animation progress. Perhaps instead of running your animation in a loop, you can make your animation run only once. And then once you monitored it had finished running and stopped, you can start it again, so you can keep track of how many times it has started.