animate method

SequenceAnimation animate(
  1. AnimationController controller
)

The controllers duration is going to be overwritten by this class, you should not specify it on your own

Implementation

SequenceAnimation animate(AnimationController controller) {
  int longestTimeMicro = _currentLengthInMicroSeconds();
  // Sets the duration of the controller
  controller.duration = new Duration(microseconds: longestTimeMicro);

  Map<Object, Animatable> animatables = {};
  Map<Object, double> begins = {};
  Map<Object, double> ends = {};

  _animations.forEach((info) {
    assert(info.to.inMicroseconds <= longestTimeMicro);

    double begin = info.from.inMicroseconds / longestTimeMicro;
    double end = info.to.inMicroseconds / longestTimeMicro;
    Interval intervalCurve = new Interval(begin, end, curve: info.curve);
    if (animatables[info.tag] == null) {
      animatables[info.tag] =
          IntervalAnimatable.chainCurve(info.animatable, intervalCurve);
      begins[info.tag] = begin;
      ends[info.tag] = end;
    } else {
      assert(
          ends[info.tag]! <= begin,
          "When animating the same property you need to: \n"
          "a) Have them not overlap \n"
          "b) Add them in an ordered fashion\n"
          "Animation with tag ${info.tag} ends at ${ends[info.tag]} but also begins at $begin"
      );
      animatables[info.tag] = new IntervalAnimatable(
        animatable: animatables[info.tag]!,
        defaultAnimatable:
            IntervalAnimatable.chainCurve(info.animatable, intervalCurve),
        begin: begins[info.tag]!,
        end: ends[info.tag]!,
      );
      ends[info.tag] = end;
    }
  });

  Map<Object, Animation> result = {};

  animatables.forEach((tag, animInfo) {
    result[tag] = animInfo.animate(controller);
  });

  return new SequenceAnimation._internal(result);
}