contrastRatio method

double contrastRatio(
  1. Color other
)

Returns the WCAG contrast ratio between this color and other (1–21).

Colors.black.contrastRatio(Colors.white) // 21.0

Implementation

double contrastRatio(Color other) {
  final l1 = luminance + 0.05;
  final l2 = other.luminance + 0.05;
  return l1 > l2 ? l1 / l2 : l2 / l1;
}