skip to Main Content

Since color.value is deprecated in Flutter 2.17,
Colors.red.value, gives 'value' is deprecated and shouldn't be used. Use component accessors like .r or .g..
How do you get HEX value of a color? Not only green, red or blue values but HEX value?

 int get value {
    return _floatToInt8(a) << 24 |
        _floatToInt8(r) << 16 |
        _floatToInt8(g) << 8 |
        _floatToInt8(b) << 0;
  }

Should we now write this depricated method ourselves or is there better way?

2

Answers


  1. There will be a replacement method toARGB32() in the next version. Until then you can use the deprecated getter or re-implement it. I would just wait until toARGB32() makes it into the stable Flutter version.

    Login or Signup to reply.
  2. String rgbToHex(Color color) {
      return '${color.red.toRadixString(16).padLeft(2, '0')}${color.green.toRadixString(16).padLeft(2, '0')}${color.blue.toRadixString(16).padLeft(2, '0')}';
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search