Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide after animation completes #24

Closed
CyberGhost007 opened this issue Mar 2, 2020 · 3 comments
Closed

Hide after animation completes #24

CyberGhost007 opened this issue Mar 2, 2020 · 3 comments

Comments

@CyberGhost007
Copy link

How can I hide lottie after the animation completes?

@xvrh
Copy link
Owner

xvrh commented Mar 2, 2020

I added an example that shows how to hide the animation when complete:
https://github.com/xvrh/lottie-flutter/blob/master/example/lib/examples/hide_after_complete.dart

The important part are:

Add a status listener on the animation controller and update a variable when the animation is completed.

    _animationController = AnimationController(vsync: this)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          setState(() {
            _showAnimation = false;
          });
        }
      });

Conditionally display the animation

if (_showAnimation)
  Lottie.asset(
    'assets/LottieLogo1.json',
     controller: _animationController,
     onLoaded: (composition) {
       animationController
          ..duration = composition.duration
          ..reset()
          ..forward();
        },
  ),

@luis-cruzt
Copy link

It works like charm.

@CyberGhost007
Copy link
Author

Awesome, thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants