hnvn / flutter_shimmer

A package provides an easy way to add shimmer effect in Flutter project
BSD 3-Clause "New" or "Revised" License
1.8k stars 205 forks source link

Synchronize multiple `Shimmers` automatically #24

Open JonasWanke opened 4 years ago

JonasWanke commented 4 years ago

Currently, to synchronize multiple widgets showing shimmers, you have to create a Shimmer wrapping all those widgets. This also doesn't allow us to add any non-shimmering widget inside.

Maybe, instead of calculating the progress locally for each Shimmer, you could globally synchronize them by transforming local to global offsets (RenderBox.localToGlobal) and using a global time (DateTime.now()). The Shimmer's position would then be, e.g. for ShimmerDirection.ltr:

final progress = (DateTime.now().millisecondsSinceEpoch / period.inMilliseconds) % 1;
final position = width * progress - localToGlobal(offset).dx;

Pros

Cons

Hannnes1 commented 1 year ago

Another solution would be to use the same approach that is described in the cookbook. It uses a single, top level widget to synchronize all the descendants.