Color class Null safety

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.
Implementers

Constructors

Color(int value)
Construct a color from the lower 32 bits of an int.
const
Color.fromARGB(int a, int r, int g, int b)
Construct a color from the lower 8 bits of four integers.
const
Color.fromRGBO(int r, int g, int b, double opacity)
Create a color from red, green, blue, and opacity, similar to rgba() in CSS.
const

Properties

alpha int
The alpha channel of this color in an 8 bit value.
read-only
blue int
The blue channel of this color in an 8 bit value.
read-only
green int
The green channel of this color in an 8 bit value.
read-only
hashCode int
The hash code for this object.
read-onlyoverride
opacity double
The alpha channel of this color as a double.
read-only
red int
The red channel of this color in an 8 bit value.
read-only
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
value int
A 32 bit value representing this color.
final

Methods

computeLuminance() double
Returns a brightness value between 0 for darkest and 1 for lightest.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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).

Operators

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

Static Methods

alphaBlend(Color foreground, Color background) Color
Combine the foreground color as a transparent color over top of a background color, and return the resulting combined color.
getAlphaFromOpacity(double opacity) int
Returns an alpha value representative of the provided opacity value.
lerp(Color? a, Color? b, double t) Color?
Linearly interpolate between two colors.