funwithflutter/flutter_confetti

Cannot listen to the controller state (e;.g. if animation finished)

Closed this issue · 2 comments

It would be very nice to be able to listen to the state of a Confetti controller.
For example in one of my apps I create confetti controller on the fly and there is no way to remove them when the animation is done like you can do with AnimationController when you listen to the statut of the animation.

I have the same problem. The listener is only called when animation starts.
Also, it is not possible to access ConfettiControllerState in order to compare the current state of the controller with some value.

Something seems to be wrong with the controller state and/or the listener handling.
If I use the example code https://github.com/funwithflutter/flutter_confetti/blob/master/example/lib/main.dart and add a listener to the top center controller like so:

  @override
  void initState() {
    _controllerCenter =
        ConfettiController(duration: const Duration(seconds: 10));
    _controllerCenterRight =
        ConfettiController(duration: const Duration(seconds: 10));
    _controllerCenterLeft =
        ConfettiController(duration: const Duration(seconds: 10));
    _controllerTopCenter =
        ConfettiController(duration: const Duration(seconds: 10));
    _controllerBottomCenter =
        ConfettiController(duration: const Duration(seconds: 10));

    _controllerTopCenter.addListener(() {
      print("STATE CHANGED: " + _controllerTopCenter.state.toString());
    });
    super.initState();
  }

When tapping the top center button I get the following output:

I/flutter ( 4743): STATE CHANGED: ConfettiControllerState.playing

It is the only output I get. When the animation is finished, there is no more output from the listener.