Skip to content

Commit

Permalink
Prevent reentry for loadFont
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Nov 20, 2024
1 parent 2f86ead commit 3eb75c9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/src/screenshot/load_fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ Future<void> loadFont(String family, List<String> fontPaths) async {
if (fontPaths.isEmpty) {
return;
}
final fontLoader = FontLoader(family);
for (final path in fontPaths) {
final Uint8List bytes = File(path).readAsBytesSync();
fontLoader.addFont(Future.sync(() => bytes.buffer.asByteData()));
}
// the fontLoader is unusable after calling load().
// No need to cache or return it.
await fontLoader.load();

await TestAsyncUtils.guard<void>(() async {
final fontLoader = FontLoader(family);
for (final path in fontPaths) {
final Uint8List bytes = File(path).readAsBytesSync();
fontLoader.addFont(Future.sync(() => bytes.buffer.asByteData()));
}
// the fontLoader is unusable after calling load().
// No need to cache or return it.
await fontLoader.load();
});
}

/// Loads the Roboto/RobotoCondensed/MaterialIcons fonts from the executing Flutter SDK
Expand Down

0 comments on commit 3eb75c9

Please sign in to comment.