Slowing down animations in Flutter globally Slowing down animations in Flutter globally dart dart

Slowing down animations in Flutter globally


You need set the timeDilation static property:

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).

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.