Colour.fromHex constructor
Colour.fromHex({
- required String hexString,
Implementation
factory Colour.fromHex({required String hexString}) {
String hex = hexString.replaceAll('#', '').toUpperCase();
if (hex.length == 6) {
hex = 'FF$hex';
} else if (hex.length == 3) {
hex = 'FF${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}';
} else if (hex.length == 4) {
hex =
'${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}';
}
return Colour(
alpha: int.parse(Radix.getDecimal(hex.substring(0, 2), Bases.b16)),
red: int.parse(Radix.getDecimal(hex.substring(2, 4), Bases.b16)),
green: int.parse(Radix.getDecimal(hex.substring(4, 6), Bases.b16)),
blue: int.parse(Radix.getDecimal(hex.substring(6, 8), Bases.b16)),
);
}