hslToRgbToColor static method
Implementation
static Color hslToRgbToColor(String text) {
final hslText = text.replaceAll(')', '').replaceAll(' ', '');
final hslValues = hslText.split(',').toList();
List<double?> parsedHsl = [];
for (var element in hslValues) {
if (element.contains("%") && double.tryParse(element.replaceAll("%", "")) != null) {
parsedHsl.add(double.tryParse(element.replaceAll("%", ""))! * 0.01);
} else {
if (element != hslValues.first && (double.tryParse(element) == null || double.tryParse(element)! > 1)) {
parsedHsl.add(null);
} else {
parsedHsl.add(double.tryParse(element));
}
}
}
if (parsedHsl.length == 4 && !parsedHsl.contains(null)) {
return HSLColor.fromAHSL(parsedHsl.last!, parsedHsl.first!, parsedHsl[1]!, parsedHsl[2]!).toColor();
} else if (parsedHsl.length == 3 && !parsedHsl.contains(null)) {
return HSLColor.fromAHSL(1.0, parsedHsl.first!, parsedHsl[1]!, parsedHsl.last!).toColor();
} else {
return Colors.black;
}
}