dart - Listen for an animation to complete -


i'm trying perform action after animation finishes. tried adding statuslistener not working me. code looks 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 animation end. going wrong?

///---edit---///

i'm using animatedbuilder, part of code looks 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,     );   }, ), 

reacting comment , edit looked animationbuilder. adapting example in docs came working solution:

class spinner extends statefulwidget {   @override   _spinnerstate createstate() => new _spinnerstate(); }  class _spinnerstate extends state<spinner> singletickerproviderstatemixin {   animationcontroller _controller;   curvedanimation _animation;    @override   void initstate() {     super.initstate();     _controller = new animationcontroller(       duration: const duration(seconds: 5),       vsync: this,     )..forward();      _animation = new curvedanimation(         parent: _controller,         curve: curves.linear,     )..addstatuslistener((animationstatus status) {       if (status == animationstatus.completed)         print('completed');     });   }    @override   void dispose() {     _controller.dispose();     super.dispose();   }    @override   widget build(buildcontext context) {     return new animatedbuilder(       animation: _animation,       child: new container(width: 200.0, height: 200.0, color: colors.green),       builder: (buildcontext context, widget child) {         return new transform.rotate(           angle: _controller.value * 2.0 * 3.1415,           child: child,         );       },     );   } } 

as can see, used controller parent animation, used animation animationbuilder. hope helps.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -