Listen for an animation to complete

Reacting to your comment and edit I looked into the AnimationBuilder. Adapting the example in the docs I came up with this working solution:

class Spinner extends StatefulWidget {
  @override
  _SpinnerState createState() => new _SpinnerState();
}

class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CurvedAnimation _animation;

  @override
  void initState() {
    super.initState();
    _controller = new AnimationController(
      duration: const Duration(seconds: 5),
      vsync: this,
    )..forward();

    _animation = new CurvedAnimation(
        parent: _controller,
        curve: Curves.linear,
    )..addStatusListener((AnimationStatus status) {
      if (status == AnimationStatus.completed)
        print('completed');
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new AnimatedBuilder(
      animation: _animation,
      child: new Container(width: 200.0, height: 200.0, color: Colors.green),
      builder: (BuildContext context, Widget child) {
        return new Transform.rotate(
          angle: _controller.value * 2.0 * 3.1415,
          child: child,
        );
      },
    );
  }
}

As you can see, I used the controller as parent to an animation, which was than used as animation for the AnimationBuilder. Hope it helps.


Following the example in the flutter gallery's progress indicators you should attach the StatusListener to an animation, not the controller

_controller = AnimationController(
  duration: const Duration(milliseconds: 1500),
  vsync: this,
)..forward();

_animation = CurvedAnimation(
  parent: _controller,
  curve: const Interval(0.0, 0.9, curve: Curves.fastOutSlowIn),
  reverseCurve: Curves.fastOutSlowIn
)..addStatusListener((AnimationStatus status) {
  if (status == AnimationStatus.dismissed)
    _controller.forward();
  else if (status == AnimationStatus.completed)
    _controller.reverse();
});

I have not tested this with your code. Just shout, if it doesn't work ;)