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?
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?
Share Improve this question asked Jan 19 at 13:21 ChrisChris 1,0272 gold badges18 silver badges36 bronze badges2 Answers
Reset to default 3There 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.
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')}';
}