Comments (1)
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)
- support for Flutter 3 HOT 2
- Chaining animations? HOT 1
- Control play/stop/reverse animations without GlobalKey ? HOT 1
- Migrate to null safety HOT 1
- Animator not working on Web? HOT 3
- AnimationPreferences bug with autoPlay PingPong HOT 2
- How to adjust the animation distance? HOT 4
- Replay animation on navigation back to page HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from animator.