in lib/src/property.dart [226:276]
static String? _convertCssToArgb(String value) {
// TODO(terry): Better parser/regex for converting CSS properties.
var color = value.trim().replaceAll('\\s', '');
if (color[0] == '#') {
var v = color.substring(1);
Color.hexToInt(v); // Valid hexadecimal, throws if not.
return v;
} else if (color.isNotEmpty && color[color.length - 1] == ')') {
int type;
if (color.indexOf('rgb(') == 0 || color.indexOf('RGB(') == 0) {
color = color.substring(4);
type = _rgbCss;
} else if (color.indexOf('rgba(') == 0 || color.indexOf('RGBA(') == 0) {
type = _rgbaCss;
color = color.substring(5);
} else if (color.indexOf('hsl(') == 0 || color.indexOf('HSL(') == 0) {
type = _hslCss;
color = color.substring(4);
} else if (color.indexOf('hsla(') == 0 || color.indexOf('HSLA(') == 0) {
type = _hslaCss;
color = color.substring(5);
} else {
throw UnsupportedError('CSS property not implemented');
}
color = color.substring(0, color.length - 1); // Strip close paren.
var args = <num>[];
var params = color.split(',');
for (var param in params) {
args.add(double.parse(param));
}
switch (type) {
case _rgbCss:
return Color.convertToHexString(
args[0].toInt(), args[1].toInt(), args[2].toInt());
case _rgbaCss:
return Color.convertToHexString(
args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3]);
case _hslCss:
return Hsla(args[0], args[1], args[2]).toHexArgbString();
case _hslaCss:
return Hsla(args[0], args[1], args[2], args[3]).toHexArgbString();
default:
// Type not defined UnsupportedOperationException should have thrown.
assert(false);
break;
}
}
return null;
}