Contrast class

Utility methods for calculating contrast given two colors, or calculating a color given one color and a contrast ratio.

Contrast ratio is calculated using XYZ's Y. When linearized to match human perception, Y becomes HCT's tone and Lab*'s' L*. Informally, this is the lightness of a color.

Methods refer to tone, T in the the HCT color space. Tone is equivalent to L* in the Lab* color space, or L in the LCH color space.

Constructors

Contrast()

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

darker({required double tone, required double ratio}) double
Returns a tone <= tone that ensures ratio. Return value is between 0 and 100. Returns -1 if ratio cannot be achieved with tone.
darkerUnsafe({required double tone, required double ratio}) double
Returns a tone <= tone that ensures ratio. Return value is between 0 and 100. Returns 0 if ratio cannot be achieved with tone.
lighter({required double tone, required double ratio}) double
Returns a tone >= tone that ensures ratio. Return value is between 0 and 100. Returns -1 if ratio cannot be achieved with tone.
lighterUnsafe({required double tone, required double ratio}) double
Returns a tone >= tone that ensures ratio. Return value is between 0 and 100. Returns 100 if ratio cannot be achieved with tone.
ratioOfTones(double toneA, double toneB) double
Returns a contrast ratio, which ranges from 1 to 21. toneA Tone between 0 and 100. Values outside will be clamped. toneB Tone between 0 and 100. Values outside will be clamped.