ArnaDynamicColor class

A Color subclass that represents a family of colors, and the correct effective color in the color family.

When used as a regular color, ArnaDynamicColor is equivalent to the effective color (i.e. ArnaDynamicColor.value will come from the effective color), which is determined by the BuildContext it is last resolved against. If it has never been resolved, the light, normal contrast ArnaDynamicColor.color will be the default effective color.

Sometimes manually resolving an ArnaDynamicColor is not necessary, because the Arna Library provides built-in support for it.

Using an ArnaDynamicColor from an ArnaTheme

When referring to an ArnaTheme color, generally the color will already have adapted to the ambient BuildContext , because ArnaTheme.of implicitly resolves all the colors used in the retrieved ArnaThemeData, before returning it.

{@tool snippet} The following code sample creates a Container with the accentColor of the current theme. If accentColor is a ArnaDynamicColor, the container will be adaptive, thanks to ArnaTheme.of: it will switch to accentColor's dark variant once dark mode is turned on, and turns to accentColor`'s high contrast variant when MediaQueryData.highContrast is requested in the ambient MediaQuery, etc.

Container(
  // Container is not an Arna widget, but ArnaTheme.of implicitly
  // resolves colors used in the retrieved ArnaThemeData.
  color: ArnaTheme.of(context).accentColor,
)

{@end-tool}

Manually Resolving an ArnaDynamicColor

When used to configure a non-Arna widget, or wrapped in an object opaque to the receiving Arna component, a ArnaDynamicColor may need to be manually resolved using ArnaDynamicColor.resolve, before it can used to paint.

{@tool snippet}

The following code samples demonstrate a cases where you have to manually resolve an ArnaDynamicColor.

Container(
  // Container is not an Arna widget.
  color: ArnaDynamicColor.resolve(ArnaColors.accentColor, context),
)

{@end-tool}

See also:

Inheritance
Mixed in types
Annotations

Constructors

ArnaDynamicColor({String? debugLabel, required Color color, required Color darkColor, required Color highContrastColor, required Color darkHighContrastColor})
Creates an adaptive Color that changes its effective color based on the BuildContext given. The default effective color is color.
const

Properties

alpha int
The alpha channel of this color in an 8 bit value.
no setterinherited
blue int
The blue channel of this color in an 8 bit value.
no setterinherited
color Color
The color to use when the BuildContext implies a combination of light mode and normal contrast.
final
darkColor Color
The color to use when the BuildContext implies a combination of dark mode and normal contrast.
final
darkHighContrastColor Color
The color to use when the BuildContext implies a combination of dark mode and high contrast.
final
green int
The green channel of this color in an 8 bit value.
no setterinherited
hashCode int
The hash code for this object.
no setteroverride
highContrastColor Color
The color to use when the BuildContext implies a combination of light mode and high contrast.
final
opacity double
The alpha channel of this color as a double.
no setterinherited
red int
The red channel of this color in an 8 bit value.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value int
A 32 bit value representing this color.
no setteroverride

Methods

computeLuminance() double
Returns a brightness value between 0 for darkest and 1 for lightest.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveFrom(BuildContext context) ArnaDynamicColor
Resolves this ArnaDynamicColor using the provided BuildContext.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
override
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited
withAlpha(int a) Color
Returns a new color that matches this color with the alpha channel replaced with a (which ranges from 0 to 255).
inherited
withBlue(int b) Color
Returns a new color that matches this color with the blue channel replaced with b (which ranges from 0 to 255).
inherited
withGreen(int g) Color
Returns a new color that matches this color with the green channel replaced with g (which ranges from 0 to 255).
inherited
withOpacity(double opacity) Color
Returns a new color that matches this color with the alpha channel replaced with the given opacity (which ranges from 0.0 to 1.0).
inherited
withRed(int r) Color
Returns a new color that matches this color with the red channel replaced with r (which ranges from 0 to 255).
inherited

Operators

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

Static Methods

applyOverlay(Color backgroundColor) Color
Applies an overlay color to a backgroundColor.
estimateBrightnessForColor(Color color) Brightness
Determines whether the given Color is Brightness.light or Brightness.dark.
matchingColor(Color color, Brightness brightness) Color
Computes the color that matches with color and brightness.
maybeResolve(Color? resolvable, BuildContext context) Color?
Resolves the given Color by calling resolveFrom.
onBackgroundColor(Color backgroundColor) Color
A color that's clearly legible when drawn on backgroundColor.
outerColor(Color color) Color
The color to use when drawn outside of color.
resolve(Color resolvable, BuildContext context) Color
Resolves the given Color by calling resolveFrom.