string - flutter/Dart : Convert HEX color string t

我们的数据库将颜色保存为像“#AABBCC”这样的String,所以我基本上在寻找这样的函数:Color.parseColor("#AABBCC"); Flutter

Color 类需要这样的 Color(0xFF42A5F5) 所以我需要将 "#AABBCC" 转换为 0xFFAABBCC

最佳答案

/// Construct a color from a hex code string, of the format #RRGGBB.
Color hexToColor(String code) {
  return new Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000);
}

关于string - flutter/Dart : Convert HEX color string to Color?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50381968/

相关文章:

dart - 每 x 秒 flutter 一次运行功能

dart - flutter 垂直视口(viewport)无界高度错误

android - 在 Scroll Flutter 上隐藏 Appbar?

flutter - 保留选项卡 View 页面之间的状态

dart - Flutter - 翻牌效果

flutter - 当 Flutter TextField 中的键盘可见时,键盘顶部有很多空白区域

google-maps - Flutter中的谷歌地图没有响应触摸事件

flutter - 小部件测试失败,未找到任何 MediaQuery 小部件

android - 为什么我的 Flutter 应用的 ListView 滚动不如 Flutter

android - Flutter 中的 HTTP 请求