resolveFontWeight static method

FontWeight resolveFontWeight(
  1. String? fontWeight
)

Implementation

static FontWeight resolveFontWeight(String? fontWeight) {
  switch (fontWeight) {
    case 'lighter':
      return FontWeight.w200;
    case 'normal':
      return FontWeight.w400;
    case 'bold':
      return FontWeight.w700;
    case 'bolder':
      return FontWeight.w900;
    default:
      int? fontWeightValue;
      if (fontWeight != null) {
        fontWeightValue = int.tryParse(fontWeight);
      }
      // See: https://drafts.csswg.org/css-fonts-4/#font-weight-numeric-values
      // Only values greater than or equal to 1, and less than or equal to 1000, are valid,
      // and all other values are invalid.
      if (fontWeightValue == null || fontWeightValue > 1000 || fontWeightValue <= 0) {
        return FontWeight.w400;
      } else if (fontWeightValue >= 900) {
        return FontWeight.w900;
      } else if (fontWeightValue >= 800) {
        return FontWeight.w800;
      } else if (fontWeightValue >= 700) {
        return FontWeight.w700;
      } else if (fontWeightValue >= 600) {
        return FontWeight.w600;
      } else if (fontWeightValue >= 500) {
        return FontWeight.w500;
      } else if (fontWeightValue >= 400) {
        return FontWeight.w400;
      } else if (fontWeightValue >= 300) {
        return FontWeight.w300;
      } else if (fontWeightValue >= 200) {
        return FontWeight.w200;
      } else {
        return FontWeight.w100;
      }
  }
}