getColorWithHexString static method
根据十六进制颜色值字符串,转颜色
Implementation
static Color getColorWithHexString(String hexColor,
{Color defaultColor = Colors.transparent}) {
if (hexColor.isEmpty) return defaultColor;
Color? color = colorsDic[hexColor];
if (color != null) return color;
hexColor = hexColor.toUpperCase().replaceAll("#", "");
hexColor = hexColor.replaceAll('0X', '');
if (hexColor.length == 6) {
hexColor = "FF$hexColor";
}
if (hexColor.length != 8) return defaultColor;
return Color(int.tryParse(hexColor, radix: 16) ?? 0x00000000);
}