tryCampaignFontWeight function
Parses a valid dashboard font weight or returns null for invalid input.
Implementation
int? tryCampaignFontWeight(Object? value) {
final normalized = value?.toString().trim().toLowerCase();
final named = switch (normalized) {
'thin' => 100,
'extralight' || 'extra_light' => 200,
'light' => 300,
'normal' || 'regular' => 400,
'medium' => 500,
'semibold' || 'semi_bold' => 600,
'bold' => 700,
'extrabold' || 'extra_bold' => 800,
'heavy' || 'black' => 900,
_ => null,
};
final numeric = named ?? int.tryParse(normalized ?? '');
return numeric != null && numeric >= 100 && numeric <= 900 ? numeric : null;
}