Table of Contents
Flutter uses Flutter Material Colors Class and Flutter Dart-UI Color Class to paint colors on your app screen.
Flutter Colors Demo |
Flutter Material Colors Class - Documentation
Also refer official class documentation with this guide to deeply understand the concept.
Let us start with the simplest way to apply colors to your flutter app widgets.
color : Colors.orange
Colors Class Constants |
Orange Container Widget UI |
Darker Orange Shade - Colors.orange[900] |
How to use color shade value ?
Both of the above methods have same output
Colors.orange[900] |
Colors.orange.shade900 |
Both the above methods have same output
Color Shade Orange 900 UI |
Note : Colors.orange is same as Colors.orange[500] or Colors.orange.shade500
Example
Colors.black12 - pure black with 12 % opacity
White & Black Colors |
Note : Transparent Color - Colors.transparent constant - entirely invisble
Flutter Dart-UI - Color Class - Documentation
Also refer official class documentation with this guide to deeply understand the concept.
Let us first understand the basics of colors.
Alpha Property - Docs
Alpha Property Summary
8 bit value - 0 (transparent) to 255 (opaque)
Opacity Property - Docs
Opacity Property Summary
double value - 0.0 (transparent) to 1.0 (opaque)
Color represented as 32 bit value
Bits are assigned as follows :
Difference between Alpha and Opacity
Alpha sets alpha channel value in 8 bit value and Opacity sets alpha channel value in double
Let us also understand what is 0xFFFFA726 ?
Orange Int Value |
In the common “hash syntax” we represent color values as #FFA726 (Ignore 0xFF at the beginning).
color picker tool |
Using a color picker tool, we get the same color ie. Colors.orange[400] using “hash syntax” #FFA726
If we convert hex code to decimal code, we can get the RGB values.
Thus, 0xFFFFA726 is 0x FF(alpha) FF(red) A7(green) 26(blue)
Now, we have understood all the basics of color values and color channels we can now proceed with implementation code of the constructors of the Color class
color : Color.fromARGB (255,255,167,38) // fromARGB Decimal
ARGB int |
Note : Add 0x to the value, for example, Green channel (hex) A7 will become 0xA7
color : Color.fromARGB (0xFF,0xFF,0xA7,0x26) // fromARGB Hex
ARGB Hex |
color : Color.fromRGBO(255,167,38,1.0) // fromRGBO Decimal
RGBO |
color : Color(0xFFFFA726) // int value
Color Int Value |
Output UI Color for all above 4 constructor is same
Color Constructor Output |