getColorWithHexString static method

Color getColorWithHexString(
  1. String hexColor, {
  2. Color defaultColor = Colors.transparent,
})

根据十六进制颜色值字符串,转颜色

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);
}