Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/google_fonts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.2.1

- Fixes `pendingFonts()` retaining failed font loads.

## 8.2.0

- Extract the class `Config` to its own file and rename it `GoogleFontsConfig`. The `Config` class is now deprecated.
Expand Down
6 changes: 3 additions & 3 deletions packages/google_fonts/lib/src/google_fonts_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void clearCache() => _loadedFonts.clear();

/// Set of [Future]s corresponding to fonts that are loading.
///
/// When a font is loading, a future is added to this set. When it is loaded in
/// the [FontLoader], that future is removed from this set.
/// When a font is loading, a future is added to this set. When the load
/// completes, whether successfully or with an error, that future is removed.
final Set<Future<void>> pendingFontFutures = <Future<void>>{};

/// Default client used to fetch fonts when one is not supplied.
Expand Down Expand Up @@ -106,7 +106,7 @@ TextStyle googleFontsTextStyle({

final Future<void> loadingFuture = loadFontIfNecessary(descriptor);
pendingFontFutures.add(loadingFuture);
loadingFuture.then((_) => pendingFontFutures.remove(loadingFuture));
loadingFuture.whenComplete(() => pendingFontFutures.remove(loadingFuture)).ignore();

return textStyle.copyWith(
fontFamily: familyWithVariant.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/google_fonts/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_fonts
description: A Flutter package to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.
repository: https://github.com/flutter/packages/tree/main/packages/google_fonts
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
version: 8.2.0
version: 8.2.1

environment:
sdk: ^3.10.0
Expand Down
15 changes: 15 additions & 0 deletions packages/google_fonts/test/load_font_if_necessary_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ final GoogleFontsDescriptor fakeDescriptor = GoogleFontsDescriptor(
file: _fakeResponseFile,
);

final Map<GoogleFontsVariant, GoogleFontsFile> _fakeFonts = <GoogleFontsVariant, GoogleFontsFile>{
fakeDescriptor.familyWithVariant.googleFontsVariant: fakeDescriptor.file,
};

// Same family & variant, different file.
final GoogleFontsDescriptor fakeDescriptorDifferentFile = GoogleFontsDescriptor(
familyWithVariant: fakeDescriptor.familyWithVariant,
Expand Down Expand Up @@ -361,4 +365,15 @@ void main() {
returnsNormally,
);
});

test('pendingFonts removes failed font loads', () async {
when(mockHttpClient.gets(any)).thenAnswer((_) async {
return http.Response('', 404);
});

googleFontsTextStyle(fontFamily: fakeDescriptor.familyWithVariant.family, fonts: _fakeFonts);

await expectLater(GoogleFonts.pendingFonts(), throwsException);
expect(await GoogleFonts.pendingFonts(), isEmpty);
});
}