rive-app / rive-flutter

Flutter runtime for Rive
https://rive.app
MIT License
1.21k stars 191 forks source link

How do I start new animation after one finishes #75

Closed jay-iamin closed 3 years ago

jay-iamin commented 3 years ago

I have 2 animations, named "initial" and "looper", "initial" runs only once and "looper" runs in a loop . How do I start "looper" animation when "initial" ends.

Thanks for your help

yeasin50 commented 3 years ago

on State decleare 2 Simple animation;

SimpleAnimation initial=  SimpleAnimation('initial');
SimpleAnimation looper=  SimpleAnimation('looper');

on initState add initial at controller.

inside initState add Timer to check animation status like :

Timer(Duration(milliseconds: 400), () {
      initial.isActiveChanged.addListener(() {
        if (initial.isActive == false) {
          log("initial anim ended ✌");
          SchedulerBinding.instance.addPostFrameCallback((_) {
            ///  `remove  initial animation and add looper `
             _riveArtboard.artboard.removeController(initial);
             _riveArtboard.artboard.addController(looper);

          });

also you can check my code here

mjohnsullivan commented 3 years ago

We've posted an example of how to use the new RiveAnimation widget with one-shot animations, which shows how to listen for when a one-shot completes: https://help.rive.app/runtimes/playback#repeatedly-playing-a-one-shot-animation