Slowing down animations in Flutter globally

Multi tool use
Multi tool use


Slowing down animations in Flutter globally



There is a function or method in the Flutter framework, which can be used to ajust the animation/running speed of every widget.



This is possible using I think a service.



I just forgot how I can call it and could not find any resources that describes it + I do not know where I once discovered it.



There is not really more information to provide as this is just a simple one liner. I hope that someone knows what I am talking about.





do you mean the slow motion option in the flutter Gallery app ?
– Raouf Rahiche
Jun 30 at 16:57






@RaoufRahiche I could have looked at that source if I knew about it :) I wanted to say that I knew about timeDilation some time back, but forgot the package and property names :)
– creativecreatorormaybenot
Jun 30 at 19:40


timeDilation




1 Answer
1



You need set the timeDilation static property:


timeDilation


import 'package:flutter/scheduler.dart' show timeDilation;
// you can also import the whole file:
// import 'package:flutter/scheduler.dart';

...

timeDilation = 2.0; // Will slow down animations by a factor of two



I am using show in my import because it limits the import to certain declarations from the library.
In this context I only want to be able to use timeDilation from the scheduler.dart library, and nothing else. Since schedulers are pretty low-level things, this makes sense to not pollute the namespace. There's also hide that has the opposite effect (only hides certain declarations).


show


import


timeDilation


scheduler.dart


hide



You can set this from anywhere in your app, even in the main function:


import 'package:flutter/scheduler.dart' show timeDilation;

void main() {
timeDilation = 3.0;
runApp(new MyApp());
}



or in your pressed handler:


onPressed: () => timeDilation = 2.0



This is a global static property so you don't need to call setState in order for the changes to take place.


setState





Yep, that's the one. Not upvoting because it should be very obvious that setState does not need to be called. Animations are not connected to state. No build update needed for animations because they are not part of the build tree. Also I think that onPressed is a strange addition. Maybe remove that or something and explain what show timeDilation does and why you think that it should be included. Thank you a lot :)
– creativecreatorormaybenot
Jun 30 at 19:38



setState


onPressed


show timeDilation





> it should be very obvious that setState does not need to be called -- maybe for you, not for everyone; > Animations are not connected to state -- animations are connected to the state, scheduling isn't, isn't that right? > I think that onPressed is a strange addition. Maybe remove that -- I'm sorry that my answer contains more information than just timeDilation from 'package:flutter/scheduler.dart'. I think an example is useful for people looking for information about time dilation in general. Why is it too much and explaining show` isn't?
– wasyl
Jun 30 at 19:56



timeDilation


. I think an example is useful for people looking for information about time dilation in general. Why is it too much and explaining





Sorry, I did not mean it in a negative way. I just think that some parts were strange, e.g. onPressed is completely out of context and I still do not know what show does in your code :) You asked about scheduling and yes that is of course what I tried to say because that is the part of the animation that makes it an animation. Gave you an upvote now, but I still want to know what show does :) I do not want you to explain the concept of show, it would just be nice to explain why you chose to include it (I mean it is obvious if you know what it does).
– creativecreatorormaybenot
Jun 30 at 21:27



onPressed


show


show


show





Sorry if I came out overtly negative as well, I just wanted the answer to be more accessible somehow. As for show, it limits import to certain declarations from the library -- in this context I only want to be able to use timeDilation from the scheduler.dart library, and nothing else. Since schedulers are pretty low-level thing this makes sense to not pollute the namespace. There's also hide that has the opposite effect (only hides certain declarations)
– wasyl
Jun 30 at 21:44


show


timeDilation


scheduler.dart


hide






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

N3c08bqrzf6aToPRx u1bdbc8oQotD2T,qsutkVh,tMbo
kku7bnKyPWX i03FZrBsDhAoMFyL3s4,F7sdKRdJ0RwRclx dafDQ7oFxKbEXdn,PFKK,eFm,R,Z4vV69mRB

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters