applyLayerAnimationCurve function

double applyLayerAnimationCurve(
  1. AnimationCurve curve,
  2. double t
)

Eases t (0–1) with curve exactly as the native renderer in pro_video_editor does (applyEasing in ApplyAnimation.kt/.swift).

Flutter's own Curves are close but not the same — its ease curves are cubic Béziers and its elastic curves swing with another period — so the timeline preview uses this instead, and shows what the export renders.

Implementation

double applyLayerAnimationCurve(AnimationCurve curve, double t) {
  switch (curve) {
    case AnimationCurve.linear:
      return t;
    case AnimationCurve.easeIn:
      return t * t;
    case AnimationCurve.easeOut:
      return t * (2 - t);
    case AnimationCurve.easeInOut:
      return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
    case AnimationCurve.easeInCubic:
      return t * t * t;
    case AnimationCurve.easeOutCubic:
      final p = 1 - t;
      return 1 - p * p * p;
    case AnimationCurve.easeInOutCubic:
      return t < 0.5 ? 4 * t * t * t : 1 - math.pow(-2 * t + 2, 3) / 2;
    case AnimationCurve.bounceIn:
      return 1 - _bounceOut(1 - t);
    case AnimationCurve.bounceOut:
      return _bounceOut(t);
    case AnimationCurve.bounceInOut:
      return t < 0.5
          ? (1 - _bounceOut(1 - 2 * t)) / 2
          : (1 + _bounceOut(2 * t - 1)) / 2;
    case AnimationCurve.elasticIn:
      return 1 - _elasticOut(1 - t);
    case AnimationCurve.elasticOut:
      return _elasticOut(t);
    case AnimationCurve.elasticInOut:
      return t < 0.5
          ? (1 - _elasticOut(1 - 2 * t)) / 2
          : (1 + _elasticOut(2 * t - 1)) / 2;
  }
}