animateTo method

void animateTo(
  1. String key,
  2. double from,
  3. double to,
  4. Duration duration,
  5. Curve curve,
)

Implementation

void animateTo(String key, double from, double to, Duration duration, Curve curve) {
  if (animationMap.containsKey(key)) {
    final animation = animationMap[key]!;
    animation.tween.begin = from;
    animation.tween.end = to;

    if (from != to) {
      animation.controller.stop();
      animation.controller.reset();
      animation.controller.forward();
    }

    return;
  }

  final controller = AnimationController(vsync: vsync, duration: duration)
    ..addListener(notifyListeners)
    ..addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        animationMap.remove(key)?.controller.dispose();
      }
    })
    ..forward();

  animationMap[key] = (
    controller: controller,
    curve: curve,
    tween: Tween(begin: from, end: to)
  );
}