DynamicColor class final
A color that adjusts itself based on UI state, represented by DynamicScheme.
This color automatically adjusts to accommodate a desired contrast level, or other adjustments such as differing in light mode versus dark mode, or what the theme is, or what the color that produced the theme is, etc.
Colors without backgrounds do not change tone when contrast changes. Colors with backgrounds become closer to their background as contrast lowers, and further when contrast increases.
For example, the default behavior of adjust tone at max contrast to be at a 7.0 ratio with its background is principled and matches accessibility guidance. That does not mean it's the desired approach for every design system, and every color pairing, always, in every case.
Ultimately, each component necessary for calculating a color, adjusting it for a desired contrast level, and ensuring it has a certain lightness/tone difference from another color, is provided by a function that takes a DynamicScheme and returns a value. This ensures ultimate flexibility, any desired behavior of a color for any design system, but is usually unnecessary.
@param name The name of the dynamic color. @param palette Function that provides a TonalPalette given DynamicScheme. A TonalPalette is defined by a hue and chroma, so this replaces the need to specify hue/chroma. By providing a tonal palette, when contrast adjustments are made, intended chroma can be preserved. @param isBackground Whether this dynamic color is a background, with some other color as the foreground. @param chromaMultiplier Function that provides a chroma multiplier, given a DynamicScheme. @param background Function that provides a background color, given a DynamicScheme. @param tone Function that provides a tone, given a DynamicScheme. @param secondBackground Function that provides a second background color, given a DynamicScheme. @param contrastCurve Function that provides a contrast curve, given a DynamicScheme. @param toneDeltaPair Function that provides a tone delta pair, given a DynamicScheme. @param opacity Function that provides an opacity percentage, given a DynamicScheme.
Constructors
-
DynamicColor({required String name, required DynamicSchemeCallback<
TonalPalette> palette, bool isBackground = false, DynamicSchemeCallback<double> ? chromaMultiplier, DynamicSchemeCallback<DynamicColor?> ? background, DynamicSchemeCallback<double> ? tone, DynamicSchemeCallback<DynamicColor?> ? secondBackground, DynamicSchemeCallback<ContrastCurve?> ? contrastCurve, DynamicSchemeCallback<ToneDeltaPair?> ? toneDeltaPair, DynamicSchemeCallback<double?> ? opacity}) - DynamicColor.fromArgb(String name, int argb)
-
Create a DynamicColor from a hex code.
factory
Properties
-
background
→ DynamicSchemeCallback<
DynamicColor?> ? -
Function that provides a background color, given a DynamicScheme.
final
-
chromaMultiplier
→ DynamicSchemeCallback<
double> ? -
Function that provides a chroma multiplier, given a DynamicScheme.
final
-
contrastCurve
→ DynamicSchemeCallback<
ContrastCurve?> ? -
Function that provides a contrast curve, given a DynamicScheme.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- isBackground → bool
-
Whether this dynamic color is a background,
with some other color as the foreground.
final
- name → String
-
The name of the dynamic color.
final
-
opacity
→ DynamicSchemeCallback<
double?> ? -
Function that provides an opacity percentage, given a DynamicScheme.
final
-
palette
→ DynamicSchemeCallback<
TonalPalette> -
Function that provides a TonalPalette given DynamicScheme.
A TonalPalette is defined by a hue and chroma, so this replaces
the need to specify hue/chroma. By providing a tonal palette,
when contrast adjustments are made, intended chroma can be preserved.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
secondBackground
→ DynamicSchemeCallback<
DynamicColor?> ? -
Function that provides a second background color, given a DynamicScheme.
final
-
tone
→ DynamicSchemeCallback<
double> -
Function that provides a tone, given a DynamicScheme.
final
-
toneDeltaPair
→ DynamicSchemeCallback<
ToneDeltaPair?> ? -
Function that provides a tone delta pair, given a DynamicScheme.
final
Methods
-
copyWith(
{String? name, DynamicSchemeCallback< TonalPalette> ? palette, DynamicSchemeCallback<double> ? tone, bool? isBackground}) → DynamicColor -
extendSpecVersion(
SpecVersion specVersion, DynamicColor extendedColor) → DynamicColor -
getArgb(
DynamicScheme scheme) → int -
getHct(
DynamicScheme scheme) → Hct -
getTone(
DynamicScheme scheme) → double -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
enableLightForeground(
double tone) → double -
foregroundTone(
double bgTone, double ratio) → double -
getInitialToneFromBackground(
[DynamicSchemeCallback< DynamicColor?> ? background]) → DynamicSchemeCallback<double> -
toneAllowsLightForeground(
double tone) → bool -
tonePrefersLightForeground(
double tone) → bool