Reputation: 126704
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 describe 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.
Upvotes: 18
Views: 12396
Reputation: 3506
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.
Upvotes: 57