computeLuminance method
Returns a brightness value between 0 for darkest and 1 for lightest.
Represents the relative luminance of the color. This value is computationally expensive to calculate.
See en.wikipedia.org/wiki/Relative_luminance.
Copied from Flutter's Color class.
Implementation
double computeLuminance() {
final rgb = toRgbColor();
// See <https://www.w3.org/TR/WCAG20/#relativeluminancedef>
final red = _linearizeColorComponent(rgb.red / 0xFF);
final green = _linearizeColorComponent(rgb.green / 0xFF);
final blue = _linearizeColorComponent(rgb.blue / 0xFF);
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
}