parse static method

CSSColor? parse(
  1. String? color
)

Implementation

static CSSColor? parse(String? color) {
  if (color == null) return null;

  var cssColor = CSSColorHEX.parse(color);
  if (cssColor != null) return cssColor;

  var matchRGB = CSSColorRGB.patternRGB.firstMatch(color);
  if (matchRGB != null) {
    //var type = int.parse( match.group(1) ) ;
    var red = int.parse(matchRGB.group(2)!);
    var green = int.parse(matchRGB.group(3)!);
    var blue = int.parse(matchRGB.group(4)!);
    var alpha = parseDouble(matchRGB.group(5));

    if (alpha != null && alpha != 1) {
      return CSSColorRGBA(red, green, blue, alpha);
    } else {
      return CSSColorRGB(red, green, blue);
    }
  }

  return CSSColorName.parse(color);
}