ContrastValidator class

Validates color contrast ratios for accessibility compliance.

Implements WCAG 2.1 contrast ratio calculations and provides methods to check if color combinations meet accessibility standards.

Example:

final isAccessible = ContrastValidator.meetsWcagAA(
  foreground: Colors.blue,
  background: Colors.white,
);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

contrastRatio(Color foreground, Color background) double
Calculates the contrast ratio between two colors.
describeRatio(double ratio) String
Gets a readable description of a contrast ratio.
meetsLevel(Color foreground, Color background, ContrastLevel level) bool
Checks if a color combination meets a specific WCAG level.
meetsWcagAA(Color foreground, Color background) bool
Checks if a color combination meets WCAG AA for normal text.
meetsWcagAA3(Color foreground, Color background) bool
Checks if a color combination meets WCAG AA for large text/UI components.
meetsWcagAAA(Color foreground, Color background) bool
Checks if a color combination meets WCAG AAA for normal text.
suggestAccessibleColor(Color foreground, Color background, {ContrastLevel level = ContrastLevel.aa}) Color
Suggests an adjusted color that meets the target contrast level.
validatePalette(List<Color> colors, Color background, {ContrastLevel level = ContrastLevel.aa}) Map<int, ContrastIssue>
Validates a color palette against a background.