Skip to content

@color

Declares a named color value resource.

Declaration

<resources xmlns="https://xwidget.dev/values">
    <color name="primary">0xFF28B6F6</color>
    <color name="background">#FFFFFF</color>
    <color name="textDark">#262626</color>
    <color name="accent">0xFFFF5722</color>
</resources>
Attribute Description Required
name Unique key for the value Yes

Color values can be specified as hex strings with or without the 0x prefix. The # shorthand is also supported. Values are parsed into Flutter Color objects.

Fragment Usage

Reference with the @color/ directive:

<Container color="@color/background">
    <Text data="Hello" color="@color/textDark"/>
</Container>

Dart Usage

final primary = Resources.instance.getColor("primary");
final primaryHex = Resources.instance.getColorString("primary");

getColor() returns a Color object. getColorString() returns the color as a string. Both throw an exception if the resource name is not found.

See Also