Giter Club home page Giter Club logo

Comments (1)

senorprogramador avatar senorprogramador commented on August 11, 2024

Hi @roopa1712 ,

The answer is: by default animations only play once on the first widget's init. My guess is that your code accidentally re-adds the parent, creating an entirely new animation instance. Meaning animation is performed again.
Further more, please note animations replay once when hot-reload is performed.

You can set the specific play-mode (forward, loop, pingpong or reverse) by passing in an AnimationPreferences instance with the desired AnimationPlayStates enum.

If you want more control over when and how to run animations, you can also pass in a GlobalKey.
See below for an example.

Example: More control by passing a GlobalKey.

class MyHomePage extends StatelessWidget {
  ///Use a GlobalKey to gain access to the [AnimatorWidgetState],
  ///every animated widget from the flutter_animator package uses this state.
  final GlobalKey<AnimatorWidgetState> _animationKey =
      GlobalKey<AnimatorWidgetState>();

  MyHomePage();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Animate once'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            FadeInRight(
                ///We pass in the _animationKey to control our animation
                key: _animationKey,
                preferences: AnimationPreferences(
                  autoPlay: AnimationPlayStates.None,
                ),
                child: Text(
                  'FadeInRight',
                  textAlign: TextAlign.center,
                )),
            FloatingActionButton(
              onPressed: () {
                ///Animate forward once, using the _animationKey supplied
                ///to the BounceInDownWidget above.
                _animationKey.currentState.forward();
              },
              child: Text('Animate Once'),
            )
          ],
        ),
      ),
    );
  }
}

You could also keep track of a shouldAnimate boolean in a parent statefull widget and pass in the AnimationPlayStates enum accordingly.

If the above example does not work for you, please supply some code so I can help you further.
Just reopen the issue if problems persist.

Good luck!

Kind regards,

Sjoerd van den Berg.

from animator.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.