fromHex method
Convert hex to color
Implementation
Color fromHex(String hexString) {
if (hexString.startsWith("#") && hexString.length == 9) {
int? alpha = int.tryParse(hexString.substring(1, 3), radix: 16);
int? colorValue = int.tryParse(hexString.substring(3, 9), radix: 16);
if (alpha != null && colorValue != null) {
return Color.fromARGB(
0xff,
colorValue >> 16,
(colorValue >> 8) & 0xFF,
colorValue & 0xFF,
).withOpacity(alpha / 255);
}
}
return Colors.transparent;
}