weight static method

FontWeight? weight(
  1. String value
)

A font weight from 100 … 900, or thin, extra-light, light, normal / regular, medium, semibold, bold, extra-bold, black; null otherwise.

Implementation

static FontWeight? weight(String value) {
  final text = value.trim().toLowerCase().replaceAll(RegExp('[-_ ]'), '');
  final number = int.tryParse(text);
  if (number != null) {
    return number % 100 == 0 && number >= 100 && number <= 900
        ? FontWeight.values[number ~/ 100 - 1]
        : null;
  }
  return switch (text) {
    'thin' => FontWeight.w100,
    'extralight' => FontWeight.w200,
    'light' => FontWeight.w300,
    'normal' || 'regular' => FontWeight.w400,
    'medium' => FontWeight.w500,
    'semibold' => FontWeight.w600,
    'bold' => FontWeight.w700,
    'extrabold' => FontWeight.w800,
    'black' => FontWeight.w900,
    _ => null,
  };
}