parseStFontWeightValue function

int? parseStFontWeightValue(
  1. Object? raw,
  2. String path
)

Implementation

int? parseStFontWeightValue(Object? raw, String path) {
  if (raw == null) return null;
  if (raw is num) {
    final n = raw.round();
    if (n < 100 || n > 900 || n % 100 != 0) {
      throw FormatException('$path unknown fontWeight $raw');
    }
    return n;
  }
  if (raw is String) {
    final s = raw.toLowerCase().replaceAll('-', '').replaceAll('_', '');
    switch (s) {
      case 'thin':
        return 100;
      case 'extralight':
        return 200;
      case 'light':
        return 300;
      case 'regular':
      case 'normal':
        return 400;
      case 'medium':
        return 500;
      case 'semibold':
        return 600;
      case 'bold':
        return 700;
      case 'extrabold':
        return 800;
      case 'black':
        return 900;
      default:
        if (s.startsWith('w') && s.length > 1) {
          return parseStFontWeightValue(int.parse(s.substring(1)), path);
        }
        throw FormatException('$path unknown fontWeight "$raw"');
    }
  }
  throw FormatException('$path unknown fontWeight $raw');
}