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

时间:2018-05-22 17:23:50

标签: dart flutter

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

2 个答案:

答案 0 :(得分:3)

您可以聆听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);

答案 1 :(得分:3)

您也可以使用它:

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