toColor method

Color toColor()

This colour as a Flutter Color, for a caller showing an engine colour in a widget.

The channels are encoded with the sRGB curve. A colour inside 0..1 comes back in ColorSpace.sRGB; one brighter than white or outside the gamut comes back in ColorSpace.extendedSRGB, so nothing is clipped before the widget decides how to draw it.

Implementation

Color toColor() {
  final srgb = toSrgb();
  final inGamut = <double>[
    srgb.r,
    srgb.g,
    srgb.b,
  ].every((double c) => c >= 0 && c <= 1);
  return Color.from(
    alpha: a.clamp(0, 1).toDouble(),
    red: srgb.r,
    green: srgb.g,
    blue: srgb.b,
    colorSpace: inGamut ? ColorSpace.sRGB : ColorSpace.extendedSRGB,
  );
}