Home > Net >  How can i convert hex color code to color name or rgb value?
How can i convert hex color code to color name or rgb value?

Time:05-28

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

CodePudding user response:

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.

CodePudding user response:

Its simple new Color(0xFF373334) should work

or

 Color(0xFF373334).red
    Color(0xFF373334).green
    Color(0xFF373334).blue

CodePudding user response:

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);
  • Related