contrastRatio static method
Calculate the contrast ratio between two Color objects.
Implementation
static double contrastRatio(Color textColor, Color backgroundColor) {
double textLuminance = calculateLuminance(textColor);
double backgroundLuminance = calculateLuminance(backgroundColor);
double lighter = textLuminance > backgroundLuminance
? textLuminance
: backgroundLuminance;
double darker = textLuminance > backgroundLuminance
? backgroundLuminance
: textLuminance;
return (lighter + 0.05) / (darker + 0.05);
}