我试图在动画完成后执行动作。我尝试添加一个statusListener,但这不适合我。我的代码如下所示:试听动画以完成
@override
void initState() {
super.initState();
_controller = new AnimationController(
duration: new Duration(milliseconds: 500),
vsync: this,
)..addStatusListener((AnimationStatus status) {
print("Going");
if (status.index == 3 && spins > 0) { // AnimationStatus index 3 == completed animation
_controller.duration = new Duration(milliseconds: speed - 50);
_controller.forward(from: _controller.value == null ? 0.0 : 1 - _controller.value);
spins--;
print(speed);
}
});
}
print(Going);
永远不会执行,但我的动画结束。出了什么问题?
/// ---编辑--- ///
我使用的是AnimatedBuilder
的那部分代码如下所示:
child: new AnimatedBuilder(
animation: _controller,
child: new Image.network(widget.url),
builder: (BuildContext context, Widget child) {
return new Transform.rotate(
angle: _controller.value * 2.0 * math.PI,
child: child,
);
},
),
我忘了说我正在使用'AnimatedBuilder'(我编辑了我的文章并添加了一些代码)。我认为我不能将你的方法应用到我写的东西上,还有其他想法吗? –