0

The thing is i have an hex color code which is pass to another screen and when i go to another screen i wanna convert that hex color code to color name or to rgb value is that possible? need some help here.

This is my hex color code value type #ff373334
Saurav
  • 132
  • 1
  • 12
  • https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter#:~:text=Create%20a%20variable%20of%20type,you%20are%20ready%20to%20go. – Anmol Mishra May 27 '22 at 07:31

3 Answers3

0

Its simple new Color(0xFF373334) should work

or

 Color(0xFF373334).red
    Color(0xFF373334).green
    Color(0xFF373334).blue
Paweł
  • 205
  • 2
  • 11
0

the package color_models will help you convert a Hex color to CMYK, HSI, HSL, HSP, HSB, LAB, Oklab, RGB, and XYZ.

It's straightforward to use, and if you need a custom implementation, you can check the repository of the package to see how each model work to convert your Hex color to RGB.

BLKKKBVSIK
  • 3,128
  • 2
  • 13
  • 33
0

You can use it like this.

   hexStringToColor(String hexColor) {
  hexColor = hexColor.toUpperCase().replaceAll("#", "");
  if (hexColor.length == 6) {
    hexColor = "FF" + hexColor;
  }
  return Color(int.parse(hexColor, radix: 16));
}

Now you can call this function anywhere like this.

Color color = hexStringToColor(hexString);
Maqsood
  • 807
  • 3
  • 14