resolved property

Gradient resolved

Returns the literal Gradient result that this interpreted IntermediateGradient represents with its interpolated packet, a GradientPacket with its own t keyframe, and primitive basic gradient representation with colors and stops.

The lists of colors and stops should already be same length by this point, but something may have happened along the way through lerping or hot restarting that leaves a few cycles with dissimilar values.

This getter will secure their lengths to a safe value.

Implementation

Gradient get resolved {
  if (packet.gradient is LinearSteps) {
    return (_copyWith(packet.gradient,
            colors: colors,
            stops: stops,
            transform: packet.transform,
            tileMode: packet.tileMode,
            begin: packet.begin,
            end: packet.end,
            softness: packet.softness,
            shadeFunction: packet.shadeFunction,
            shadeFactor: packet.shadeFactor,
            distance: packet.distance) as LinearSteps)
        .asGradient;
  } else if (packet.gradient is RadialSteps) {
    return (_copyWith(packet.gradient,
            colors: colors,
            stops: stops,
            transform: packet.transform,
            tileMode: packet.tileMode,
            center: packet.center,
            radius: packet.radius,
            focal: packet.focal,
            focalRadius: packet.focalRadius,
            softness: packet.softness,
            shadeFunction: packet.shadeFunction,
            shadeFactor: packet.shadeFactor,
            distance: packet.distance) as RadialSteps)
        .asGradient;
  } else if (packet.gradient is SweepSteps) {
    return (_copyWith(packet.gradient,
            colors: colors,
            stops: stops,
            transform: packet.transform,
            tileMode: packet.tileMode,
            center: packet.center,
            startAngle: packet.startAngle,
            endAngle: packet.endAngle,
            softness: packet.softness,
            shadeFunction: packet.shadeFunction,
            shadeFactor: packet.shadeFactor,
            distance: packet.distance) as SweepSteps)
        .asGradient;
  }

  final safeLength = math.min(colors.length, stops?.length ?? colors.length);
  final safeColors =
      //  (packet.gradient is Steps) ? packet.gradient.steppedColors :
      <Color>[for (int i = 0; i < safeLength; i++) colors[i]];
  final safeStops =
      // (packet.gradient is Steps) ? packet.gradient.steppedStops :
      stops != null
          ? <double>[for (int i = 0; i < safeLength; i++) stops![i]]
          : stops;

  return _copyWith(
    packet.gradient,
    colors: safeColors,
    stops: safeStops,
    transform: packet.transform,
    tileMode: packet.tileMode,
    begin: packet.begin,
    end: packet.end,
    center: packet.center,
    radius: packet.radius,
    focal: packet.focal,
    focalRadius: packet.focalRadius,
    startAngle: packet.startAngle,
    endAngle: packet.endAngle,
    softness: packet.softness,
    shadeFunction: packet.shadeFunction,
    shadeFactor: packet.shadeFactor,
    distance: packet.distance,
  );
}