PrimitiveGradient.byCombination constructor

PrimitiveGradient.byCombination(
  1. Gradient a,
  2. Gradient b,
  3. double t
)

Vanilla Flutter gradient merge process.

Creates a new collection.SplayTreeSet with all stops from a & b then maps a list of Colors to that set of all stops.

The mapped colors will still represent those of gradient a when t is 0.0 and represent gradient b when t is 1.0 by individually Color.lerping each mapping between a sample from a and another sample from b at the same keyframe t.

Implementation

factory PrimitiveGradient.byCombination(Gradient a, Gradient b, double t) {
  var aStops = /* a is Steps ? a.steppedStops : */ interpretStops(a);
  var bStops = /* b is Steps ? b.steppedStops : */ interpretStops(b);

  final stops = collection.SplayTreeSet<double>()
    ..addAll(aStops)
    ..addAll(bStops);
  final interpolatedStops = stops.toList(growable: false);

  // final stops = <double>[];
  // var stops = aStops + bStops;
  // var stops = aStops;
  // for (var stop in bStops) {
  //   if (!aStops.contains(stop)) stops.add(stop);
  // }
  // if ((t < 0.5 && b is Steps) || b is! Steps) stops.addAll(aStops);
  // if ((t > 0.5 && a is Steps) || a is! Steps) stops.addAll(bStops);
  // final interpolatedStops = stops..sort();

  // final isDecal =
  //     a.tileMode == TileMode.decal || b.tileMode == TileMode.decal;
  final interpolatedColors = interpolatedStops
      .map<Color>(
        (double stop) => Color.lerp(
          // sample(a is Steps ? a.steppedColors : a.colors, aStops, stop),
          // sample(b is Steps ? b.steppedColors : b.colors, bStops, stop),
          sample(a.colors, aStops, stop /*, isDecal*/),
          sample(b.colors, bStops, stop /*, isDecal*/),
          t,
        )!,
      )
      .toList(growable: false);
  return PrimitiveGradient._(interpolatedColors, interpolatedStops);
}