Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make animation value always run from 0 to 1

I’m trying to create an animation tween from 0 to 1:

final Tween<double> _tween = Tween(begin: 0, end: 1);

late AnimationController _controller;

late Animation<double> _animation;

And for some reason, sometimes I need to call _controller.reverse() or _controller.forward(), and my animation.value runs from 0 to 1 then from 1 to 0.

How do I always get animation.value to run from 0 to 1?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do it with _controller.forward(from: 0) or you can create a function to get animation value like this:

double getAnimationValue(Animation animation) {
    final value = animation.value!;

    return animation.status == AnimationStatus.reverse ? 1 - value : value;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading