After complete the widget animation run a function in Flutter

You can listen on the status of an AnimationController:

var _controller = new AnimationController(
    0.0, 
    const Duration(milliseconds: 200),
);

_controller.addStatusListener((status) {
  if(status == AnimationStatus.completed) {
    // custom code here
  }
});    

Animation<Offset> _animation = new Tween<Offset>(
  begin: const Offset(100.0, 50.0),
  end: const Offset(200.0, 300.0),
).animate(_controller);

also you can use this :

_animationController.forward().whenComplete(() {
 // put here the stuff you wanna do when animation completed!
});

You can simple do:

_controller.forward().then((value) => {
      //run code when end
});

This run the animation forward(you can use reverse or any other modes) and call to //run code when end when it end. Acording to official docs, .forward(): Returns a [TickerFuture] that completes when the animation is complete.

So using the then of the Future api over the TickerFuture returned in _controller.forward() you can execute any code when the animation completed.

Tags:

Dart

Flutter