parseStyle method Null safety

void parseStyle(
  1. BuildMetadata meta,
  2. Declaration style
)

Parses inline style key and value pair.

Implementation

void parseStyle(BuildMetadata meta, css.Declaration style) {
  final key = style.property;
  switch (key) {
    case kCssBackground:
    case kCssBackgroundColor:
      _styleBgColor ??= StyleBgColor(this).buildOp;
      meta.register(_styleBgColor!);
      break;

    case kCssColor:
      final color = tryParseColor(style.value);
      if (color != null) {
        meta.tsb.enqueue(TextStyleOps.color, color);
      }
      break;

    case kCssDirection:
      meta.tsb.enqueue(TextStyleOps.textDirection, style.term);
      break;

    case kCssFontFamily:
      final list = TextStyleOps.fontFamilyTryParse(style.values);
      meta.tsb.enqueue(TextStyleOps.fontFamily, list);
      break;

    case kCssFontSize:
      meta.tsb.enqueue(TextStyleOps.fontSize, style.value);
      break;

    case kCssFontStyle:
      final term = style.term;
      final fontStyle =
          term != null ? TextStyleOps.fontStyleTryParse(term) : null;
      if (fontStyle != null) {
        meta.tsb.enqueue(TextStyleOps.fontStyle, fontStyle);
      }
      break;

    case kCssFontWeight:
      final value = style.value;
      final fontWeight =
          value != null ? TextStyleOps.fontWeightTryParse(value) : null;
      if (fontWeight != null) {
        meta.tsb.enqueue(TextStyleOps.fontWeight, fontWeight);
      }
      break;

    case kCssHeight:
    case kCssMaxHeight:
    case kCssMaxWidth:
    case kCssMinHeight:
    case kCssMinWidth:
    case kCssWidth:
      _styleSizing ??= StyleSizing(this).buildOp;
      meta.register(_styleSizing!);
      break;

    case kCssLineHeight:
      _tsbLineHeight ??= TextStyleOps.lineHeight(this);
      meta.tsb.enqueue(_tsbLineHeight!, style.value);
      break;

    case kCssMaxLines:
    case kCssMaxLinesWebkitLineClamp:
      final maxLines = tryParseMaxLines(style.value);
      if (maxLines != null) {
        meta.maxLines = maxLines;
      }
      break;

    case kCssTextAlign:
      final term = style.term;
      if (term != null) {
        meta.register(StyleTextAlign(this, term).op);
      }
      break;

    case kCssTextDecoration:
    case kCssTextDecorationColor:
    case kCssTextDecorationLine:
    case kCssTextDecorationStyle:
    case kCssTextDecorationThickness:
    case kCssTextDecorationWidth:
      _styleTextDecoration ??= StyleTextDecoration(this).op;
      meta.register(_styleTextDecoration!);
      break;

    case kCssTextOverflow:
      final textOverflow = tryParseTextOverflow(style.value);
      if (textOverflow != null) {
        meta.overflow = textOverflow;
      }
      break;

    case kCssVerticalAlign:
      _styleVerticalAlign ??= StyleVerticalAlign(this).buildOp;
      meta.register(_styleVerticalAlign!);
      break;

    case kCssWhitespace:
      final term = style.term;
      final whitespace =
          term != null ? TextStyleOps.whitespaceTryParse(term) : null;
      if (whitespace != null) {
        meta.tsb.enqueue(TextStyleOps.whitespace, whitespace);
      }
      break;
  }

  if (key.startsWith(kCssBorder)) {
    _styleBorder ??= StyleBorder(this).buildOp;
    meta.register(_styleBorder!);
  }

  if (key.startsWith(kCssMargin)) {
    _styleMargin ??= StyleMargin(this).buildOp;
    meta.register(_styleMargin!);
  }

  if (key.startsWith(kCssPadding)) {
    _stylePadding ??= StylePadding(this).buildOp;
    meta.register(_stylePadding!);
  }
}