flutterFontWeight property

FontWeight flutterFontWeight

Convert text defined fontWeights like "Bold" into Flutter types, like w700. Source: https://cssreference.io/property/font-weight/.

Implementation

FontWeight get flutterFontWeight {
  // This is used for layouts exported after April 30, 2021.
  if (weight != null) return weight!.flutterFontWeight;

  // Deprecated

  // Convert 'extra-bold' or 'extra bold' into 'extrabold'.
  final String style =
      this.style.toLowerCase().replaceAll('-', '').replaceAll(' ', '');

  // String might contain 'italic', which is why it uses [contains] for the
  // comparison.
  if (style.contains('thin')) {
    return FontWeight.w100;
  } else if (style.contains('extralight')) {
    return FontWeight.w200;
  } else if (style.contains('light')) {
    return FontWeight.w300;
  } else if (style.contains('normal')) {
    return FontWeight.w400;
  } else if (style.contains('medium')) {
    return FontWeight.w500;
  } else if (style.contains('semibold')) {
    return FontWeight.w600;
  } else if (style.contains('extrabold')) {
    // order matters, extrabold must come before bold.
    return FontWeight.w800;
  } else if (style.contains('ultrabold')) {
    // order matters, ultrabold must come before bold.
    return FontWeight.w900;
  } else if (style.contains('bold')) {
    return FontWeight.w700;
  } else if (style.contains('black')) {
    return FontWeight.w900;
  }

  return FontWeight.w400;
}