setShorthandBorder static method

void setShorthandBorder(
  1. Map<String, String?> properties,
  2. String property,
  3. String shorthandValue
)

Implementation

static void setShorthandBorder(Map<String, String?> properties, String property, String shorthandValue) {
  String? borderTopColor;
  String? borderRightColor;
  String? borderBottomColor;
  String? borderLeftColor;
  String? borderTopStyle;
  String? borderRightStyle;
  String? borderBottomStyle;
  String? borderLeftStyle;
  String? borderTopWidth;
  String? borderRightWidth;
  String? borderBottomWidth;
  String? borderLeftWidth;

  if (property == BORDER ||
      property == BORDER_TOP ||
      property == BORDER_RIGHT ||
      property == BORDER_BOTTOM ||
      property == BORDER_LEFT) {
    List<String?>? values = CSSStyleProperty._getBorderValues(shorthandValue);
    if (values == null) return;

    if (property == BORDER || property == BORDER_TOP) {
      borderTopWidth = values[0];
      borderTopStyle = values[1];
      borderTopColor = values[2];
    }
    if (property == BORDER || property == BORDER_RIGHT) {
      borderRightWidth = values[0];
      borderRightStyle = values[1];
      borderRightColor = values[2];
    }
    if (property == BORDER || property == BORDER_BOTTOM) {
      borderBottomWidth = values[0];
      borderBottomStyle = values[1];
      borderBottomColor = values[2];
    }
    if (property == BORDER || property == BORDER_LEFT) {
      borderLeftWidth = values[0];
      borderLeftStyle = values[1];
      borderLeftColor = values[2];
    }
  } else if (property == BORDER_WIDTH) {
    List<String?>? values = _getEdgeValues(shorthandValue, isNonNegativeLength: true);
    if (values == null) return;

    borderTopWidth = values[0];
    borderRightWidth = values[1];
    borderBottomWidth = values[2];
    borderLeftWidth = values[3];
  } else if (property == BORDER_STYLE) {
    // @TODO: validate value
    List<String?>? values = _getEdgeValues(shorthandValue);
    if (values == null) return;

    borderTopStyle = values[0];
    borderRightStyle = values[1];
    borderBottomStyle = values[2];
    borderLeftStyle = values[3];
  } else if (property == BORDER_COLOR) {
    // @TODO: validate value
    List<String?>? values = _getEdgeValues(shorthandValue);
    if (values == null) return;

    borderTopColor = values[0];
    borderRightColor = values[1];
    borderBottomColor = values[2];
    borderLeftColor = values[3];
  }

  if (borderTopColor != null) properties[BORDER_TOP_COLOR] = borderTopColor;
  if (borderRightColor != null) properties[BORDER_RIGHT_COLOR] = borderRightColor;
  if (borderBottomColor != null) properties[BORDER_BOTTOM_COLOR] = borderBottomColor;
  if (borderLeftColor != null) properties[BORDER_LEFT_COLOR] = borderLeftColor;
  if (borderTopStyle != null) properties[BORDER_TOP_STYLE] = borderTopStyle;
  if (borderRightStyle != null) properties[BORDER_RIGHT_STYLE] = borderRightStyle;
  if (borderBottomStyle != null) properties[BORDER_BOTTOM_STYLE] = borderBottomStyle;
  if (borderLeftStyle != null) properties[BORDER_LEFT_STYLE] = borderLeftStyle;
  if (borderTopWidth != null) properties[BORDER_TOP_WIDTH] = borderTopWidth;
  if (borderRightWidth != null) properties[BORDER_RIGHT_WIDTH] = borderRightWidth;
  if (borderBottomWidth != null) properties[BORDER_BOTTOM_WIDTH] = borderBottomWidth;
  if (borderLeftWidth != null) properties[BORDER_LEFT_WIDTH] = borderLeftWidth;
}