parseCssFontWeight function
解析数字或 normal/bold/bolder/lighter;未知值返回 null。
数字按最近的百位映射到 w100–w900;例如 'bold' 返回 FontWeight.w700。
Implementation
FontWeight? parseCssFontWeight(Object? value) {
final text = value is String ? value.trim().toLowerCase() : value.toString();
final keyword = switch (text) {
'normal' => FontWeight.w400,
'bold' || 'bolder' => FontWeight.w700,
'lighter' => FontWeight.w300,
_ => null,
};
if (keyword != null) return keyword;
final number = double.tryParse(text);
if (number == null || !number.isFinite) return null;
final index =
(number / _weightStep).round().clamp(1, FontWeight.values.length) - 1;
return FontWeight.values[index];
}