Reputation: 1799
In Flutter framework by extending the AnimatedWidget class is implemented a simple animation widget that changes color. How is it possible after complete the widget animation run a function?
Upvotes: 21
Views: 19110
Reputation: 432
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.
Upvotes: 3
Reputation: 1986
also you can use this :
_animationController.forward().whenComplete(() {
// put here the stuff you wanna do when animation completed!
});
Upvotes: 27
Reputation: 658087
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);
Upvotes: 38