contrastRatio method
- Color b
Calculates the contrast ratio between the current color and the given color b
.
The contrast ratio is computed based on the relative luminance of the two colors and is useful for ensuring readability and accessibility of text on backgrounds.
Returns the computed contrast ratio.
Implementation
double contrastRatio(Color b) {
final luminanceA = computeLuminance();
final luminanceB = b.computeLuminance();
if (luminanceA > luminanceB) {
return (luminanceA + 0.05) / (luminanceB + 0.05);
}
return (luminanceB + 0.05) / (luminanceA + 0.05);
}