getFontFamilyNameAndVariant function
Returns the Flutter-usable font family name for the given fontName
.
Implementation
String getFontFamilyNameAndVariant(
FontName fontName, {
FontFamilyModel? familyModel,
}) {
FontWeightNumeric weight = fontName.weight ?? FontWeightNumeric.w400;
String family = fontName.family;
String style =
fontName.style.toLowerCase().contains('italic') ? 'Italic' : 'Normal';
if (familyModel != null) {
/// If [familyModel] is not null, then this is running from the editor. In
/// this case, we need to derive the font family name from the font
/// variants.
// final FontVariantModel bestMatchedVariant = _closestMatch(
// FontVariantModel(
// weight: weight,
// style: style,
// ),
// familyModel.fontVariants,
// );
// print('Best matched variant for family $family: ${bestMatchedVariant.name} | ${bestMatchedVariant.style} | ${bestMatchedVariant.weight}');
return deriveFontFamily(
family: family,
weight: weight,
style: fontName.style,
);
}
// If [familyModel] is null, then this is running from the SDK. In this case,
// we don't need to derive the font family name since it is already processed.
return deriveFontFamily(
family: family,
style: style,
weight: weight,
);
}