skip to Main Content

I want to convert Hex color values to RGB color values. How do I do that? Sorry this question might be a bit short. but the meaning is exactly Because I haven’t seen these answers anywhere.
For example, HEX color value = "0xff4f6872" converts to RGB color value = (R:79 G:104 B:114).

I look forward to these answers, thank you.

3

Answers


  1. 0xff4f6872 isn‘t (R:79 G:104 B:114).

    A hexadecimal color is specified with: #RRGGBB. To add transparency, add two additional digits between 00 and FF.

    Here:

    ff = 256 (R)
    4f = 79 (G)
    68 = 104 (B)
    72 = 114 this means alpha = 0.45 (114/256)
    
    Login or Signup to reply.
  2. The built-in material Color class has properties that hold the color value of each color channel. You can use them to find the RGB (red, green blue) or even the RGBA (red, green, blue, alpha) value of a color.

    You first need to create a color object for your hex color by putting the value inside the Color() method and add ‘0xff’ before the hex value.

    Color myColor = Color(0xffe64a6f);
    

    You can then access any of the properties you want and use/display them however you want

    Column(
          children: [
              Text('red value: ${myColor.red}'),
              Text('green value: ${myColor.green}'),
              Text('blue value: ${myColor.blue}'),
              Text('alpha value: ${myColor.alpha}'),
          ],
    )
    
    Login or Signup to reply.
  3. The best way to convert a hexadecimal color string to RGB color values in Flutter or Dart:

    String hexColor = "0xff4f6872";
    int intColor = int.parse(hexColor);
    int red = (intColor >> 16) & 0xff;
    int green = (intColor >> 8) & 0xff;
    int blue = (intColor >> 0) & 0xff;
    

    So, you can get:
    red = 79, green = 104, blue = 114.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search