copyWith method

Gradient copyWith({
  1. List<Color>? colors,
  2. List<double>? stops,
  3. GradientTransform? transform,
  4. TileMode? tileMode,
  5. AlignmentGeometry? begin,
  6. AlignmentGeometry? end,
  7. AlignmentGeometry? center,
  8. double? radius,
  9. AlignmentGeometry? focal,
  10. double? focalRadius,
  11. double? startAngle,
  12. double? endAngle,
  13. double? softness,
  14. ColorArithmetic? shadeFunction,
  15. double? shadeFactor,
  16. double? distance,
})

📋 Returns a new copy of this Gradient with any appropriate optional parameters overriding those of this.

Recognizes LinearGradient, RadialGradient, & SweepGradient, as well as this package's LinearSteps, RadialSteps, & SweepSteps.

Defaults back to RadialGradient if Type cannot be matched. (Radial is simply a design choice.)

Gradient copyWith({
  // Universal
  List<Color>? colors, List<double>? stops, GradientTransform? transform, TileMode? tileMode,
  // Linear
  AlignmentGeometry? begin, AlignmentGeometry? end,
  // Radial or Sweep
  AlignmentGeometry? center,
  // Radial
  double? radius, AlignmentGeometry? focal, double? focalRadius,
  // Sweep
  double? startAngle, double? endAngle,
  // Steps
  double? softness
  // Shaded Steps
  ColorArithmetic? shadeFunction, double? shadeFactor, double? distance
})

Implementation

// ignore: lines_longer_than_80_chars
///   List<Color>? colors, List<double>? stops, GradientTransform? transform, TileMode? tileMode,
///   // Linear
///   AlignmentGeometry? begin, AlignmentGeometry? end,
///   // Radial or Sweep
///   AlignmentGeometry? center,
///   // Radial
///   double? radius, AlignmentGeometry? focal, double? focalRadius,
///   // Sweep
///   double? startAngle, double? endAngle,
///   // Steps
///   double? softness
///   // Shaded Steps
///   ColorArithmetic? shadeFunction, double? shadeFactor, double? distance
/// })
/// ```
Gradient copyWith({
  // Universal
  List<Color>? colors,
  List<double>? stops,
  GradientTransform? transform,
  TileMode? tileMode,
  // Linear
  AlignmentGeometry? begin,
  AlignmentGeometry? end,
  // Radial or Sweep
  AlignmentGeometry? center,
  // Radial
  double? radius,
  AlignmentGeometry? focal,
  double? focalRadius,
  // Sweep
  double? startAngle,
  double? endAngle,
  // Steps
  double? softness,
  // Shaded Steps
  ColorArithmetic? shadeFunction,
  double? shadeFactor,
  double? distance,
}) {
  if (this is PrimitiveGradient) {
    return this;
  } else if (this is IntermediateGradient) {
    final copy = this as IntermediateGradient;
    return IntermediateGradient(
      copy.primitive,
      // Packets do not carry colors or stops
      GradientPacket(
        copy.packet.a.copyWith(
          transform: transform ?? copy.packet.a.transform,
          tileMode: tileMode ?? copy.packet.a.tileMode,
          begin: begin ?? copy.packet.a.begin,
          end: end ?? copy.packet.a.end,
          center: center ?? copy.packet.a.center,
          radius: radius ?? copy.packet.a.radius,
          focal: focal ?? copy.packet.a.focal,
          focalRadius: focalRadius ?? copy.packet.a.focalRadius,
          startAngle: startAngle ?? copy.packet.a.startAngle,
          endAngle: endAngle ?? copy.packet.a.endAngle,
          softness: softness ?? copy.packet.a.softness,
          shadeFunction: shadeFunction ?? copy.packet.a.shadeFunction,
          shadeFactor: shadeFactor ?? copy.packet.a.shadeFactor,
          distance: distance ?? copy.packet.a.distance,
        ),
        copy.packet.b.copyWith(
          transform: transform ?? copy.packet.b.transform,
          tileMode: tileMode ?? copy.packet.b.tileMode,
          begin: begin ?? copy.packet.b.begin,
          end: end ?? copy.packet.b.end,
          center: center ?? copy.packet.b.center,
          radius: radius ?? copy.packet.b.radius,
          focal: focal ?? copy.packet.b.focal,
          focalRadius: focalRadius ?? copy.packet.b.focalRadius,
          startAngle: startAngle ?? copy.packet.b.startAngle,
          endAngle: endAngle ?? copy.packet.b.endAngle,
          softness: softness ?? copy.packet.b.softness,
          shadeFunction: shadeFunction ?? copy.packet.b.shadeFunction,
          shadeFactor: shadeFactor ?? copy.packet.b.shadeFactor,
          distance: distance ?? copy.packet.b.distance,
        ),
        copy.packet.t,
      ),
    );
  } else if (this is LinearGradient) {
    return (this as LinearGradient).copyWith(
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      begin: begin,
      end: end,
    );
  } else if (this is SweepGradient) {
    return (this as SweepGradient).copyWith(
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      center: center,
      startAngle: startAngle,
      endAngle: endAngle,
    );
  } else if (this is LinearShadedSteps) {
    return (this as LinearShadedSteps).copyWith(
      shadeFunction: shadeFunction,
      shadeFactor: shadeFactor,
      distance: distance,
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      begin: begin,
      end: end,
    );
  } else if (this is RadialShadedSteps) {
    return (this as RadialShadedSteps).copyWith(
      shadeFunction: shadeFunction,
      shadeFactor: shadeFactor,
      distance: distance,
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      center: center,
      radius: radius,
      focal: focal,
      focalRadius: focalRadius,
    );
  } else if (this is SweepShadedSteps) {
    return (this as SweepShadedSteps).copyWith(
      shadeFunction: shadeFunction,
      shadeFactor: shadeFactor,
      distance: distance,
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      center: center,
      startAngle: startAngle,
      endAngle: endAngle,
    );
  } else if (this is LinearSteps) {
    return (this as LinearSteps).copyWith(
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      begin: begin,
      end: end,
    );
  } else if (this is RadialSteps) {
    return (this as RadialSteps).copyWith(
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      center: center,
      radius: radius,
      focal: focal,
      focalRadius: focalRadius,
    );
  } else if (this is SweepSteps) {
    return (this as SweepSteps).copyWith(
      softness: softness,
      colors: colors,
      stops: stops,
      transform: transform,
      tileMode: tileMode,
      center: center,
      startAngle: startAngle,
      endAngle: endAngle,
    );
  } else {
    return RadialGradient(
      colors: colors ?? this.colors,
      stops: stops ?? this.stops,
      transform: transform ?? this.transform,
      tileMode: tileMode ?? this.tileMode,
      center: center ?? this.center,
      radius: radius ?? this.radius,
      focal: focal ?? this.focal,
      focalRadius: focalRadius ?? this.focalRadius,
    );
  }
}