parseBoxShadow static method

List<CSSBoxShadow>? parseBoxShadow(
  1. String present,
  2. RenderStyle renderStyle,
  3. String propertyName
)

Implementation

static List<CSSBoxShadow>? parseBoxShadow(String present, RenderStyle renderStyle, String propertyName) {

  var shadows = CSSStyleProperty.getShadowValues(present);
  if (shadows != null) {
    List<CSSBoxShadow>? boxShadow = [];
    for (var shadowDefinitions in shadows) {
      // Specifies the color of the shadow. If the color is absent, it defaults to currentColor.
      String colorDefinition = shadowDefinitions[0] ?? CURRENT_COLOR;
      Color? color = CSSColor.resolveColor(colorDefinition, renderStyle, propertyName);
      CSSLengthValue? offsetX;
      if (shadowDefinitions[1] != null) {
        offsetX = CSSLength.parseLength(shadowDefinitions[1]!, renderStyle, propertyName);
      }

      CSSLengthValue? offsetY;
      if (shadowDefinitions[2] != null) {
        offsetY = CSSLength.parseLength(shadowDefinitions[2]!, renderStyle, propertyName);
      }

      CSSLengthValue? blurRadius;
      if (shadowDefinitions[3] != null) {
        blurRadius = CSSLength.parseLength(shadowDefinitions[3]!, renderStyle, propertyName);
      }

      CSSLengthValue? spreadRadius;
      if (shadowDefinitions[4] != null) {
        spreadRadius = CSSLength.parseLength(shadowDefinitions[4]!, renderStyle, propertyName);
      }

      bool inset = shadowDefinitions[5] == INSET;

      if (color != null) {
        boxShadow.add(CSSBoxShadow(
          offsetX: offsetX,
          offsetY: offsetY,
          blurRadius: blurRadius,
          spreadRadius: spreadRadius,
          color: color,
          inset: inset,
        ));
      }
    }
    return boxShadow;
  }

  return null;
}