derivedFontFamily function
There is no way to easily load the Roboto or Cupertino fonts. To make them available in tests, a package needs to include their own copies of them.
GoldenToolkit supplies Roboto because it is free to use.
However, when a downstream package includes a font, the font family will be prefixed with /packages/
Ultimately, the font loader will load whatever we tell it, so if we see a font that looks like a Material or Cupertino font family, let's treat it as the main font family
Implementation
@visibleForTesting
String derivedFontFamily(Map<String, dynamic> fontDefinition) {
if (!fontDefinition.containsKey('family')) {
return '';
}
final String fontFamily = fontDefinition['family'];
if (_overridableFonts.contains(fontFamily)) {
return fontFamily;
}
if (fontFamily.startsWith('packages/')) {
final fontFamilyName = fontFamily.split('/').last;
if (_overridableFonts.any((font) => font == fontFamilyName)) {
return fontFamilyName;
}
} else {
for (final Map<String, dynamic> fontType in fontDefinition['fonts']) {
final String? asset = fontType['asset'];
if (asset != null && asset.startsWith('packages')) {
final packageName = asset.split('/')[1];
return 'packages/$packageName/$fontFamily';
}
}
}
return fontFamily;
}