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 c = const Color(0xFF42A5F5);
Color c = const Color.fromARGB(0xFF, 0x42, 0xA5, 0xF5);
Color c = const Color.fromARGB(255, 66, 165, 245);
Color c = 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.
- Available extensions
Constructors
- Color(int value)
-
Construct a color from the lower 32 bits of an int.
const
- Color.alphaBlend(Color foreground, Color background)
-
Combine the foreground color as a transparent color over top
of a background color, and return the resulting combined color.
factory
- 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 - Color.lerp(Color? a, Color? b, double t)
-
Linearly interpolate between two colors.
factory
Properties
- alpha → int
-
The alpha channel of this color in an 8 bit value.
no setter
- ansiParamsBackground → String
-
Available on Color, provided by the AnsiColor extension
The background ansi espace params for this Color.no setter - ansiParamsForeground → String
-
Available on Color, provided by the AnsiColor extension
The foreground ansi espace params for this Color.no setter - blue → int
-
The blue channel of this color in an 8 bit value.
no setter
- 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
- 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.
final
Methods
-
ansiWrap(
String string, {bool bg = false}) → String -
Available on Color, provided by the AnsiColor extension
Returnsstring
wrapped with ansiParamsForeground and defaultForeground or ansiParamsBackground and defaultBackground, depending onbg
. -
computeLuminance(
) → double - Returns a brightness value between 0 for darkest and 1 for lightest.
-
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).
Operators
-
operator ==(
dynamic other) → bool -
The equality operator.
override
Static Methods
-
getAlphaFromOpacity(
double opacity) → int -
Returns an alpha value representative of the provided
opacity
value.