我们的数据库将颜色保存为像“#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/