parse static method

CSSColorName? parse(
  1. String color
)
override

Implementation

static CSSColorName? parse(String color) {
  color = color.trim().toLowerCase();
  if (color.isEmpty) return null;

  var hex = colorsNames[color];
  if (hex == null) return null;

  var r = hex.substring(1, 3);
  var g = hex.substring(3, 5);
  var b = hex.substring(5, 7);
  var a = hex.length > 7 ? hex.substring(7, Math.min(9, hex.length)) : null;

  var nR = _parseHex(r);
  var nG = _parseHex(g);
  var nB = _parseHex(b);
  var nA = a != null ? _parseHex(a) / 255 : 1.0;

  return CSSColorName._(color, nR, nG, nB, nA);
}