How can I use hexadecimal color values in Flutter?

How do I convert a hexadecimal color string like #cdcded to a Color in Flutter?

@sagar

It’s really easy.

The Color class expects an ARGB integer. Since you try to use it with RGB value, represent it as int and prefix it with 0xff .

Why? Because Opacity always needs to be specified. As you may know, FF indicates full opacity.

Color mainColor = Color(0xffb74093);
1 Like