PrimitiveGradient.fromStretchLerp constructor Null safety

PrimitiveGradient.fromStretchLerp(
  1. dynamic a,
  2. dynamic b,
  3. double t
)

Interpolate two Gradients' or PrimitiveGradients' colors and stops at t.

This factory constructor will use the provided PrimitiveGradients or create them by PrimitiveGradient.from with provided Gradients but the smaller (by length of colors list) is stretchedTo have the same number of entries as the larger.

The returned PrimitiveGradient is then the result of sameLengthLerping the stretched and non-stretched gradient at the provided keyframe t.

Implementation

factory PrimitiveGradient.fromStretchLerp(dynamic a, dynamic b, double t) {
  final max = math.max(
    a is Gradient
        ? a.colors.length
        : a is PrimitiveGradient
            ? a.colors.length
            : 0,
    b is Gradient
        ? b.colors.length
        : b is PrimitiveGradient
            ? b.colors.length
            : 0,
  );
  final _a = a is PrimitiveGradient ? a : PrimitiveGradient.from(a);
  final _b = b is PrimitiveGradient ? b : PrimitiveGradient.from(b);
  // Force these gradients to have the same number of colors/stops
  final stretchedA = _a.stretchedTo(max);
  final stretchedB = _b.stretchedTo(max);
  return PrimitiveGradient.sameLengthLerp(stretchedA, stretchedB, t);

  // final lerpedColorsA =
  //     lerpListColor(a.colors, stretchedA.colors, t < 0.5 ? t * 2 : 1.0);
  // final lerpedStopsA =
  //     lerpListDouble(a.stops, stretchedA.stops, t < 0.5 ? t * 2 : 1.0);
  // final lerpedColorsB =
  //     lerpListColor(b.colors, stretchedB.colors, t < 0.5 ? t * 2 : 1.0);
  // final lerpedStopsB =
  //     lerpListDouble(b.stops, stretchedB.stops, t < 0.5 ? t * 2 : 1.0);
  //
  // print('a.stops: ${interpretStops(a)}'); // print('stretchedA.stops: ${stretchedA.stops}'); // print('\nb.stops: ${interpretStops(b)}'); // print('stretchedB.stops: ${stretchedB.stops}');
  // return PrimitiveGradient.lerp(
  //   PrimitiveGradient._(lerpedColorsA, lerpedStopsA),
  //   PrimitiveGradient._(lerpedColorsB, lerpedStopsB),
  //   t,
  // );
}