Shahzad Akram
Shahzad Akram

Reputation: 5254

Flutter reverse animation complete listener

I am trying to listen event for flutter reverse animation when it is completed but its not triggering for reverse just only for forward.

_animationController.addStatusListener((status) {
  if (status == AnimationStatus.reverse &&
      status == AnimationStatus.completed) {
    print("Reverse Animation is completed");
  }
});

Upvotes: 2

Views: 2693

Answers (2)

Shahzad Akram
Shahzad Akram

Reputation: 5254

I also figured out another approach by myself.

  _animationController.reverse().then((void) {
      // Reverse animation completed
  });

Upvotes: 3

Abdou Ouahib
Abdou Ouahib

Reputation: 886

First of all, status == AnimationStatus.reverse && status == AnimationStatus.completed is always false. status can't be equal to two values at the same time.

If you want to listen for when the animation / reverse animation is completed, use the following:

_animationController.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
    // Animation completed
  } else if (status == AnimationStatus.dismissed) {
    // Reverse animation completed
  }
});

Upvotes: 5

Related Questions