I'm trying to perform an action after my animation finishes. I tried adding a statusListener but that is not working for me. My code looks like this:
@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);
}
});
}
The print(Going);
never gets executed but my animation does end. What is going wrong?
///---Edit---///
I'm using an AnimatedBuilder
, that part of the code looks like this:
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
(I edited my post and added some code). I don't think I can apply your method to what I've written, any other ideas? – Darnelldarner