Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 776
creativecreatorormaybenot Avatar asked Jun 30 '18 16:06

creativecreatorormaybenot


People also ask

How do you delay animations in Flutter?

Interval class Null safetyAn Interval can be used to delay an animation. For example, a six second animation that uses an Interval with its begin set to 0.5 and its end set to 1.0 will essentially become a three-second animation that starts three seconds later.

What is vsync in animation Flutter?

What is vsync ? Vsync basically keeps the track of screen, so that Flutter does not renders the animation when the screen is not being displayed.

What are staggered animations in Flutter?

A staggered animation consists of sequential or overlapping animations. To create a staggered animation, use multiple Animation objects. One AnimationController controls all of the Animation s. Each Animation object specifies the animation during an Interval .

What in Flutter is a refresh rate of your animation?

Flutter aims to provide 60 frames per second (fps) performance, or 120 fps performance on devices capable of 120Hz updates. For 60fps, frames need to render approximately every 16ms.


1 Answers

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.

like image 127
wasyl Avatar answered Sep 20 '22 03:09

wasyl