withValues method

Color withValues({
  1. double? alpha,
  2. double? red,
  3. double? green,
  4. double? blue,
  5. dynamic colorSpace,
})

Returns a new color that matches this color with the passed in components changed.

Changes to color components will be applied before applying changes to the color space.

Implementation

Color withValues({
  double? alpha,
  double? red,
  double? green,
  double? blue,
  ColorSpace? colorSpace,
}) {
  Color? updatedComponents;
  if (alpha != null || red != null || green != null || blue != null) {
    updatedComponents = Color.from(
      alpha: alpha ?? a,
      red: red ?? r,
      green: green ?? g,
      blue: blue ?? b,
      colorSpace: this.colorSpace,
    );
  }
  if (colorSpace != null && colorSpace != this.colorSpace) {
    final _ColorTransform transform = _getColorTransform(
      this.colorSpace,
      colorSpace,
    );
    return transform.transform(updatedComponents ?? this, colorSpace);
  } else {
    return updatedComponents ?? this;
  }
}