colorParse static method
Implementation
static Color? colorParse(String? text) {
if (text == null) return null;
try {
String t = text.replaceAll('#', '').trim().toLowerCase();
if (!t.startsWith('0x')) {
if (t.length < 3) error('Length less than 3.');
t = switch (t.length) {
3 => 'ff${t[0]}${t[0]}${t[1]}${t[1]}${t[2]}${t[2]}',
4 => '${t[0]}${t[0]}${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}',
5 => '',
6 => 'ff$t',
7 => '',
_ => t,
};
t = '0x$t';
}
return Color(int.parse(t.take(10)));
} on Exception catch (_) {
return null;
}
}