withValues method

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

Returns a new color with the provided components updated.

Each component (alpha, red, green, blue) represents a floating-point value; see Color.from for details and examples.

If colorSpace is provided, and is different than the current color space, the component values are updated before transforming them to the provided ColorSpace.

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;
  }
}