defaultLerp<T> function

T defaultLerp<T>(
  1. T begin,
  2. T end,
  3. double time
)

A default lerp function that support all base types (Color, Size, Decoration, ...).

Implementation

T defaultLerp<T>(T begin, T end, double time) {
  final dynamic b = begin;
  final dynamic e = end;
  if (T == double) {
    return lerpDouble(b, e, time) as T;
  }
  if (T == Color) {
    return Color.lerp(b, e, time) as T;
  }
  if (T == Size) {
    return Size.lerp(b, e, time) as T;
  }
  if (T == Decoration) {
    return Decoration.lerp(b, e, time) as T;
  }
  if (T == Rect) {
    return Rect.lerp(b, e, time) as T;
  }
  if (T == EdgeInsets) {
    return EdgeInsets.lerp(b, e, time) as T;
  }
  if (T == RelativeRect) {
    return RelativeRect.lerp(b, e, time) as T;
  }
  if (T == Alignment) {
    return Alignment.lerp(b, e, time) as T;
  }
  if (T == TextStyle) {
    return TextStyle.lerp(b, e, time) as T;
  }
  if (T == Radius) {
    return Radius.lerp(b, e, time) as T;
  }
  if (T == BoxShadow) {
    return BoxShadow.lerp(b, e, time) as T;
  }
  if (T == BorderRadius) {
    return BorderRadius.lerp(b, e, time) as T;
  }
  if (T == Matrix4) {
    return Matrix4Tween(begin: b, end: e).transform(time) as T;
  }
  if (T == Border) {
    return Border.lerp(b, e, time) as T;
  }
  if (T == BorderSide) {
    return BorderSide.lerp(b, e, time) as T;
  }
  if (T == ShapeBorder) {
    return ShapeBorder.lerp(b, e, time) as T;
  }
  if (T == BoxConstraints) {
    return BoxConstraints.lerp(b, e, time) as T;
  }
  if (T == Duration) {
    return lerpDuration(b, e, time) as T;
  }

  throw Exception('Lerp not supported for begin type "$T"');
}