fontWeight method

int? fontWeight(
  1. DartValue? v
)

Implementation

int? fontWeight(DartValue? v) {
  if (v is RefValue && v.path.first == 'FontWeight') {
    const named = {'normal': 400, 'bold': 700};
    final n = named[v.last] ?? int.tryParse(v.last.replaceFirst('w', ''));
    if (n != null) return n;
  }
  final d = deref(v);
  if (d is ObjectValue && d.type == 'FontWeight') {
    // `FontWeight._(index, value)` in older SDKs, `FontWeight(value)` later.
    final values = [for (final p in d.positional) integer(p)].nonNulls;
    return values.where((w) => w >= 100).firstOrNull;
  }
  return null;
}