convertRgbToColor function
dynamic
convertRgbToColor(
- String colorToConvert,
- dynamic opacity
)
Implementation
convertRgbToColor(String colorToConvert, opacity) {
if (colorToConvert.contains("#")) {
String color = colorToConvert.replaceAll('#', '0xff');
return Color(int.parse(color));
}
var convertedString = colorToConvert
.substring(4, colorToConvert.length - 1)
.replaceAll(RegExp(' +'), ' ')
.split(',');
if (convertedString.length < 3) {
return Color.fromRGBO(255, 255, 255, opacity);
}
return Color.fromRGBO(int.parse(convertedString[0]),
int.parse(convertedString[1]), int.parse(convertedString[2]), opacity);
}