handleChange method

dynamic handleChange()

Implementation

handleChange() {
  final deps = widget.dependencies;

  bool dirty = false;

  deps.forEachIndexed((index, current) {
    final prev = previous![index];

    if (current == prev) return;

    if (prev is Color) {
      final tween = ColorTween(begin: prev, end: current);
      final animation = tween.animate(CurvedAnimation(
        parent: controller,
        curve: widget.curve,
      ));

      controller.addListener(() {
        setState(() {
          animateds![index] = animation.value ?? prev;
        });
      });
    } else {
      final tween = Tween(begin: parse(prev), end: parse(current));
      final animation = tween.animate(CurvedAnimation(
        parent: controller,
        curve: widget.curve,
      ));

      controller.addListener(() {
        setState(() {
          animateds![index] = animation.value;
        });
      });
    }

    previous![index] = current;
    dirty = true;
  });

  if (dirty) {
    controller.reset();
    controller.forward();
  }
}