flutter_hooks icon indicating copy to clipboard operation
flutter_hooks copied to clipboard

Tween hooks

Open rrousselGit opened this issue 6 years ago • 4 comments
trafficstars

Flutter offer multiple Tween classes.

A common use-case it to use them to tween between a previous and new value through didUpdateWidget.

Through hooks, this can be automated into a useTween:

final counter = useState(0);
final Tween tween = useTween(counter.value);

rrousselGit avatar Jan 25 '19 17:01 rrousselGit

something like this? :


V useTween<T extends Tween<V>, V extends dynamic>(
  V value, {
  @required T Function(V begin, V end) builder,
  Duration duration,
  double progress,
}) {
  assert(builder != null);
  assert(progress != null && duration != null);
  assert(progress == null && duration == null);
  assert(progress != null && (progress > 1.0 || progress < 1.0));

}

usage :


final color = useTween(Colors.red.shade400,
  builder: (begin, end) => ColorTween(begin: begin, end: end),
  progress: 0.5
);

sahandevs avatar Oct 15 '19 07:10 sahandevs

Flutter now has TweenAnimationBuilder so that hook is not very important.

Although if we want to make such hook, it'd be logical to use the same API as TweenAnimationBuilder:

final value = useTween(IntTween(end: 42), duration: const Duration(seconds: 2));

rrousselGit avatar Feb 17 '20 23:02 rrousselGit