flutter_animate icon indicating copy to clipboard operation
flutter_animate copied to clipboard

Animation delays cause renders

Open esDotDev opened this issue 1 year ago • 0 comments

This may not be actionable but logging this just so we can track it and potentially chat about workarounds.

Issue

When animations are delayed they force flutter to re-render at 60fps even though nothing on screen is changing.

This is due to behavior built into Flutters Ticker object, which drives AnimationController, and flutter_animates implementation of delays which rely on a long-running AnimationController that incorporates the duration of the delay into the total duration of an animation.

Each time Ticker ticks it schedules a new frame to be rendered.

Reproduction

This can be reproduced with a repeating distractor like this, which will put the app into a state of constant endless re-rendering.

  Widget build(BuildContext context) => MaterialApp(
        home: Center(
          child: FlutterLogo(size: 200)
              .animate(
                onPlay: (c) => c.repeat(),
              )
              .shimmer(delay: 2.seconds, duration: 1.seconds),
        ),
      );

You can observe the app in a state of constant re-render here:

https://github.com/gskinner/flutter_animate/assets/736973/2e2f5674-6f28-4b26-ae59-d7bff78f6188

Solution

One possible idea is to create a sub-class of Ticker that exposes a bool scheduleFrame param and can switch between a Timer based tick and a Sheduler based tick. Not sure how feasible this is, I can try and work on a proof of concept to prove viability, and then potentially we can request some tweaks to the Flutter SDK if required.

esDotDev avatar Sep 13 '23 20:09 esDotDev