toColor method
格式化为颜色
Implementation
Color? toColor() {
if (toLowerCase().startsWith('rgbo')) {
return _toRgboColor();
}
if (toLowerCase().startsWith('rgb')) {
return _toArgbColor();
}
String? value;
if (length == 10 && startsWith('0x')) {
value = this;
} else {
value = startsWith('#') ? replaceAll('#', '') : this;
if (value.length == 6) {
value = '0xFF$value';
} else if (value.length == 8) {
value = '0x$value';
}
}
final int? colorValue = int.tryParse(value);
if (colorValue == null) {
return null;
}
return Color(colorValue);
}