Never Miss a Post. Subscribe Now!

Contact Us: nawabblog@gmail.com

Location : Bangalore India.

© 2019 proudly created  by Nawab Ahmad. 

  • Nawab Ahmad
  • Grey Twitter Icon
  • Nawab Ahmad

How do I use hexadecimal color strings in Flutter?





The class Color requires an integer ARGB. If you're trying to use it with the RGB value, represent it as int and prefix 0xff to it.


Color mainColor = Color(0xffb74093);


If you are upset about this and still want to use strings, you can expand Color and add a string constructor.


class HexColor extends Color { static int _getColorFromHex(String hexColor) { hexColor = hexColor.toUpperCase().replaceAll("#", ""); if (hexColor.length == 6) { hexColor = "FF" + hexColor; } return int.parse(hexColor, radix: 16); } HexColor(final String hexColor) : super(_getColorFromHex(hexColor)); }


How to use..

Color color1 = HexColor("b74093"); Color color2 = HexColor("#b74093"); Color color3 = HexColor("#88b74093"); // if you wish to use ARGB format

2 views