最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

After color.value is deprecated in Flutter 2.17 how do you get HEX value of a color? - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a comment  | 

2 Answers 2

Reset to default 3

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.

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')}';
}
发布评论

评论列表(0)

  1. 暂无评论