parseStyle method
Parses inline style css.Declaration
one by one.
This also handles styling from BuildOps and HtmlWidget.customStylesBuilder
.
Implementation
void parseStyle(BuildTree tree, css.Declaration style) {
final key = style.property;
switch (key) {
case kCssColor:
final color = tryParseColor(style.value);
if (color != null) {
tree.inherit(text_ops.color, color);
}
break;
case kCssDirection:
final term = style.term;
if (term != null) {
tree.inherit(text_ops.textDirection, term);
}
break;
case kCssFontFamily:
final list = text_ops.fontFamilyTryParse(style.values);
tree.inherit(text_ops.fontFamily, list);
break;
case kCssFontSize:
final value = style.value;
if (value != null) {
tree.inherit(text_ops.fontSize, value);
}
break;
case kCssFontStyle:
final term = style.term;
final fontStyle =
term != null ? text_ops.fontStyleTryParse(term) : null;
if (fontStyle != null) {
tree.inherit(text_ops.fontStyle, fontStyle);
}
break;
case kCssFontWeight:
final value = style.value;
final fontWeight =
value != null ? text_ops.fontWeightTryParse(value) : null;
if (fontWeight != null) {
tree.inherit(text_ops.fontWeight, fontWeight);
}
break;
case kCssHeight:
case kCssMaxHeight:
case kCssMaxWidth:
case kCssMinHeight:
case kCssMinWidth:
case kCssWidth:
StyleSizing.registerSizingOp(this, tree);
break;
case kCssLineHeight:
final value = style.value;
if (value != null) {
tree.inherit(text_ops.lineHeight, value);
}
break;
case kCssMaxLines:
case kCssMaxLinesWebkitLineClamp:
final maxLines = tryParseMaxLines(style.value);
if (maxLines != null) {
tree.maxLines = maxLines;
}
break;
case kCssTextAlign:
tree.register(styleTextAlign);
break;
case kCssTextDecoration:
case kCssTextDecorationColor:
case kCssTextDecorationLine:
case kCssTextDecorationStyle:
case kCssTextDecorationThickness:
case kCssTextDecorationWidth:
textDecorationApply(tree, style);
break;
case kCssTextOverflow:
final textOverflow = tryParseTextOverflow(style.value);
if (textOverflow != null) {
tree.overflow = textOverflow;
}
break;
case kCssVerticalAlign:
tree.register(_styleVerticalAlign ??= StyleVerticalAlign(this).buildOp);
break;
case kCssWhitespace:
final term = style.term;
final whitespace =
term != null ? text_ops.whitespaceTryParse(term) : null;
if (whitespace != null) {
tree.inherit(text_ops.whitespace, whitespace);
}
break;
case kCssTextShadow:
textShadowApply(tree, style);
break;
}
if (key.startsWith(kCssBackground)) {
tree.register(_styleBackground ??= StyleBackground(this).buildOp);
}
if (key.startsWith(kCssBorder)) {
tree.register(_styleBorder ??= StyleBorder(this).buildOp);
}
if (key.startsWith(kCssMargin)) {
tree.register(_styleMargin ??= StyleMargin(this).buildOp);
}
if (key.startsWith(kCssPadding)) {
tree.register(_stylePadding ??= StylePadding(this).buildOp);
}
}