完成小部件动画后,在Flutter中运行一个函数

maj*_*i69 2 dart flutter

在Flutter框架中,通过扩展AnimatedWidget类实现了一个简单的动画小部件,该小部件可以更改颜色。完成小部件动画后,如何运行功能?

Moh*_*adi 9

你也可以使用这个:

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


Gün*_*uer 6

您可以侦听的状态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);
Run Code Online (Sandbox Code Playgroud)