expressionToFontSize static method

FontSize? expressionToFontSize(
  1. Expression value
)

Implementation

static FontSize? expressionToFontSize(css.Expression value) {
  if (value is css.NumberTerm) {
    return FontSize(double.tryParse(value.text));
  } else if (value is css.PercentageTerm) {
    return FontSize.percent(double.tryParse(value.text)!);
  } else if (value is css.EmTerm) {
    return FontSize.em(double.tryParse(value.text));
  } else if (value is css.RemTerm) {
    return FontSize.rem(double.tryParse(value.text)!);
  } else if (value is css.LengthTerm) {
    return FontSize(double.tryParse(value.text.replaceAll(RegExp(r'\s+(\d+\.\d+)\s+'), '')));
  } else if (value is css.LiteralTerm) {
    switch (value.text) {
      case "xx-small":
        return FontSize.xxSmall;
      case "x-small":
        return FontSize.xSmall;
      case "small":
        return FontSize.small;
      case "medium":
        return FontSize.medium;
      case "large":
        return FontSize.large;
      case "x-large":
        return FontSize.xLarge;
      case "xx-large":
        return FontSize.xxLarge;
    }
  }
  return null;
}