Color class

An immutable 32 bit color value in ARGB format.

Consider the light teal of the Flutter logo. It is fully opaque, with a red channel value of 0x42 (66), a green channel value of 0xA5 (165), and a blue channel value of 0xF5 (245). In the common "hash syntax" for color values, it would be described as #42A5F5.

Here are some ways it could be constructed:

Color c1 = const Color(0xFF42A5F5);
Color c2 = const Color.fromARGB(0xFF, 0x42, 0xA5, 0xF5);
Color c3 = const Color.fromARGB(255, 66, 165, 245);
Color c4 = const Color.fromRGBO(66, 165, 245, 1.0);

If you are having a problem with Color wherein it seems your color is just not painting, check to make sure you are specifying the full 8 hexadecimal digits. If you only specify six, then the leading two digits are assumed to be zero, which means fully-transparent:

Color c1 = const Color(0xFFFFFF); // fully transparent white (invisible)
Color c2 = const Color(0xFFFFFFFF); // fully opaque white (visible)

See also:

  • Colors, which defines the colors found in the Material Design specification.

Constructors

Color(int value)
Construct an sRGB color from the lower 32 bits of an int.
const
Color.from({required double alpha, required double red, required double green, required double blue, dynamic colorSpace = ColorSpace.sRGB})
Construct a color with normalized color components.
const
Color.fromARGB(int a, int r, int g, int b)
Construct an sRGB color from the lower 8 bits of four integers.
const
Color.fromRGBO(int r, int g, int b, double opacity)
Create an sRGB color from red, green, blue, and opacity, similar to rgba() in CSS.
const

Properties

a double
The alpha channel of this color.
final
alpha int
The alpha channel of this color in an 8 bit value.
no setter
b double
The blue channel of this color.
final
blue int
The blue channel of this color in an 8 bit value.
no setter
colorSpace → dynamic
The color space of this color.
final
g double
The green channel of this color.
final
green int
The green channel of this color in an 8 bit value.
no setter
hashCode int
The hash code for this object.
no setteroverride
opacity double
The alpha channel of this color as a double.
no setter
r double
The red channel of this color.
final
red int
The red channel of this color in an 8 bit value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value int
A 32 bit value representing this color.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override
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).
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).
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).
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).
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).
withValues({double? alpha, double? red, double? green, double? blue, dynamic colorSpace}) Color
Returns a new color that matches this color with the passed in components changed.

Operators

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