Skip to content

Instantly share code, notes, and snippets.

@KoheiKanagu
Created November 21, 2023 05:58
Show Gist options
  • Save KoheiKanagu/2cd9fbd379f2a8e5195a70af70e6ac17 to your computer and use it in GitHub Desktop.
Save KoheiKanagu/2cd9fbd379f2a8e5195a70af70e6ac17 to your computer and use it in GitHub Desktop.
Future<void> loadAppFonts() async {
final fontManifest = await rootBundle.loadStructuredData(
'FontManifest.json',
(string) async => json.decode(string) as Iterable<dynamic>,
);
for (final e in fontManifest) {
final loader = FontLoader(
(e as Map<String, dynamic>)['family'] as String,
);
for (final f in e['fonts'] as List<dynamic>) {
loader.addFont(
rootBundle.load((f as Map<String, dynamic>)['asset'] as String),
);
}
await loader.load();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment