resolveBackgroundSize static method

CSSBackgroundSize resolveBackgroundSize(
  1. String value,
  2. RenderStyle renderStyle,
  3. String propertyName
)

Implementation

static CSSBackgroundSize resolveBackgroundSize(String value, RenderStyle renderStyle, String propertyName) {
  switch (value) {
    case CONTAIN:
      return CSSBackgroundSize(
        fit: BoxFit.contain
      );
    case COVER:
      return CSSBackgroundSize(
        fit: BoxFit.cover
      );
    case AUTO:
      return CSSBackgroundSize(
        fit: BoxFit.none
      );
    default:
      List<String> values = value.split(_splitRegExp);
      if (values.length == 1 && values[0].isNotEmpty) {
        CSSLengthValue width = CSSLength.parseLength(values[0], renderStyle, propertyName, Axis.horizontal);
        return CSSBackgroundSize(
          fit: BoxFit.none,
          width: width,
        );
      } else if (values.length == 2) {
        CSSLengthValue width = CSSLength.parseLength(values[0], renderStyle, propertyName, Axis.horizontal);
        CSSLengthValue height = CSSLength.parseLength(values[1], renderStyle, propertyName, Axis.vertical);
        // Value which is neither length/percentage/auto is considered to be invalid.
        return CSSBackgroundSize(
          fit: BoxFit.none,
          width: width,
          height: height,
        );
      }
      return CSSBackgroundSize(
        fit: BoxFit.none
      );
  }
}