parse static method

CSSBackground? parse(
  1. String value
)

Implementation

static CSSBackground? parse(String value) {
  var match = patternColor.firstMatch(value);
  if (match != null) {
    var colorStr = match.group(1);
    var color = CSSColor.parse(colorStr);
    return CSSBackground.color(color);
  }

  match = patternImage.firstMatch(value);
  if (match != null) {
    var imageStr = match.group(1);
    var colorStr = match.group(2);
    var color = CSSColor.parse(colorStr);

    var bgImage = CSSBackgroundImage.parse(imageStr)!;
    return CSSBackground.image(bgImage, color);
  }

  match = patternColorImage.firstMatch(value);
  if (match != null) {
    var colorStr = match.group(1);
    var color = CSSColor.parse(colorStr);
    var imageStr = match.group(2);

    var bgImage = CSSBackgroundImage.parse(imageStr)!;
    return CSSBackground.image(bgImage, color);
  }

  match = patternImages.firstMatch(value);
  if (match != null) {
    var imagesStr = match.group(1)!;
    var colorStr = match.group(2);
    var color = CSSColor.parse(colorStr);

    var matches = patternImageCapture.allMatches(imagesStr);
    var images =
        matches.map((m) => CSSBackgroundImage.parse(m.group(1))!).toList();

    return CSSBackground.images(images, color);
  }

  return null;
}