convertColor method
Implementation
Color? convertColor(String? color) {
if (color == '' || color == 'none') {
return TRANSPARENT;
}
if (color == null) {
return null;
}
var hexColorLength = [3, 4, 6, 8];
if (color == 'currentcolor') {
return this.color;
} else if (color.startsWith('rgba')) {
var componentsString =
color.split('').getRange(5, color.length - 1).join();
var components = componentsString.split(',');
return Color(
r: double.parse(components[0]),
g: double.parse(components[1]),
b: double.parse(components[2]),
a: double.parse(components[3]),
);
} else if (color.startsWith('rgb')) {
var componentsString =
color.split('').getRange(4, color.length - 1).join();
var components = componentsString.split(',');
return Color(
r: double.parse(components[0]),
g: double.parse(components[1]),
b: double.parse(components[2]),
);
} else if (color.startsWith('#') || hexColorLength.contains(color.length)) {
return Color.FromHex(color);
} else {
print('unimplented type of color: $color');
return null;
}
}