Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After complete the widget animation run a function in Flutter

Tags:

flutter

dart

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?

like image 913
majidfathi69 Avatar asked May 22 '18 17:05

majidfathi69


People also ask

How do you control animation in Flutter?

Work flow of the Flutter AnimationAnimationController(duration: const Duration(seconds: 2), vsync: this); animation = Tween<double>(begin: 0, end: 300). animate(controller); controller. forward(); Add animation based listener, addListener to change the state of the widget.

What is vsync in animation Flutter?

What is vsync ? Vsync basically keeps the track of screen, so that Flutter does not renders the animation when the screen is not being displayed.


1 Answers

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);
like image 106
Günter Zöchbauer Avatar answered Oct 15 '22 20:10

Günter Zöchbauer