Skip to content
Merged
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 @@
## 6.3.1 - 2025-07-30
### Changed
- Update AssetManifest to use the builtin Flutter API.

## 6.3.0 - 2024-11-01
### Added
- `Anton SC`
Expand Down
59 changes: 0 additions & 59 deletions packages/google_fonts/lib/src/asset_manifest.dart

This file was deleted.

38 changes: 12 additions & 26 deletions packages/google_fonts/lib/src/google_fonts_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@

import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
// TODO(andrewkolos): The flutter framework wishes to add a new class named
// `AssetManifest` to its API (see https://github.com/flutter/flutter/pull/119277).
// However, doing so would break integration tests that utilize google_fonts due
// to name collision with the `AssetManifest` class that this package already
// defines (see https://github.com/flutter/flutter/pull/119273).
// Once the AssetManifest API is added to flutter, update this package to use it
// instead of the AssetManifest class this package defines and remove this `hide`
// and the ignore annotation.
// ignore: undefined_hidden_name
import 'package:flutter/services.dart' hide AssetManifest;
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

import '../google_fonts.dart';
import 'asset_manifest.dart';
import 'file_io.dart' // Stubbed implementation by default.
// Concrete implementation if File IO is available.
if (dart.library.io) 'file_io_desktop_and_mobile.dart' as file_io;
Expand All @@ -43,7 +33,7 @@ final Set<Future<void>> pendingFontFutures = {};
http.Client httpClient = http.Client();

@visibleForTesting
AssetManifest assetManifest = AssetManifest();
AssetManifest? assetManifest;

/// Creates a [TextStyle] that either uses the [fontFamily] for the requested
/// GoogleFont, or falls back to the pre-bundled [fontFamily].
Expand Down Expand Up @@ -147,11 +137,9 @@ Future<void> loadFontIfNecessary(GoogleFontsDescriptor descriptor) async {
Future<ByteData?>? byteData;

// Check if this font can be loaded by the pre-bundled assets.
final assetManifestJson = await assetManifest.json();
assetManifest ??= await AssetManifest.loadFromAssetBundle(rootBundle);
final assetPath = _findFamilyWithVariantAssetPath(
descriptor.familyWithVariant,
assetManifestJson,
);
descriptor.familyWithVariant, assetManifest?.listAssets());
if (assetPath != null) {
byteData = rootBundle.load(assetPath);
}
Expand Down Expand Up @@ -298,20 +286,18 @@ int _computeMatch(GoogleFontsVariant a, GoogleFontsVariant b) {
/// Returns the path of the font asset if found, otherwise an empty string.
String? _findFamilyWithVariantAssetPath(
GoogleFontsFamilyWithVariant familyWithVariant,
Map<String, List<String>>? manifestJson,
List<String>? manifestValues,
) {
if (manifestJson == null) return null;
if (manifestValues == null) return null;

final apiFilenamePrefix = familyWithVariant.toApiFilenamePrefix();

for (final assetList in manifestJson.values) {
for (final String asset in assetList) {
for (final matchingSuffix in ['.ttf', '.otf'].where(asset.endsWith)) {
final assetWithoutExtension =
asset.substring(0, asset.length - matchingSuffix.length);
if (assetWithoutExtension.endsWith(apiFilenamePrefix)) {
return asset;
}
for (final asset in manifestValues) {
for (final matchingSuffix in ['.ttf', '.otf'].where(asset.endsWith)) {
final assetWithoutExtension =
asset.substring(0, asset.length - matchingSuffix.length);
if (assetWithoutExtension.endsWith(apiFilenamePrefix)) {
return asset;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/google_fonts/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: google_fonts
description: A Flutter package to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.
version: 6.3.0
version: 6.3.1
repository: https://github.com/material-foundation/flutter-packages/tree/main/packages/google_fonts
issue_tracker: https://github.com/material-foundation/flutter-packages/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
screenshots:
Expand Down
89 changes: 0 additions & 89 deletions packages/google_fonts/test/asset_manifest_test.dart

This file was deleted.

7 changes: 5 additions & 2 deletions packages/google_fonts/test/generated_font_methods_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_fonts/src/asset_manifest.dart';
import 'package:google_fonts/src/google_fonts_base.dart';
import 'package:http/http.dart' as http;
import 'package:mockito/mockito.dart';

class MockHttpClient extends Mock implements http.Client {}

class MockAssetManifest extends Mock implements AssetManifest {}
class MockAssetManifest extends Mock implements AssetManifest {
@override
List<String> listAssets() => [];
}

void main() {
setUpAll(() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_fonts/src/asset_manifest.dart';
import 'package:google_fonts/src/google_fonts_base.dart';
import 'package:google_fonts/src/google_fonts_descriptor.dart';
import 'package:google_fonts/src/google_fonts_variant.dart';
Expand All @@ -20,7 +20,10 @@ class MockHttpClient extends Mock implements http.Client {
}
}

class MockAssetManifest extends Mock implements AssetManifest {}
class MockAssetManifest extends Mock implements AssetManifest {
@override
List<String> listAssets() => [];
}

const _fakeResponse = 'fake response body - success';
// The number of bytes in _fakeResponse.
Expand Down
11 changes: 7 additions & 4 deletions packages/google_fonts/test/load_font_if_necessary_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/cupertino.dart';
// ignore: undefined_hidden_name
import 'package:flutter/services.dart' hide AssetManifest;
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_fonts/src/asset_manifest.dart';
import 'package:google_fonts/src/google_fonts_base.dart';
import 'package:google_fonts/src/google_fonts_descriptor.dart';
import 'package:google_fonts/src/google_fonts_family_with_variant.dart';
Expand All @@ -24,7 +22,12 @@ class MockHttpClient extends Mock implements http.Client {
}
}

class MockAssetManifest extends Mock implements AssetManifest {}
class MockAssetManifest extends Mock implements AssetManifest {
@override
List<String> listAssets() {
return [];
}
}

class FakePathProviderPlatform extends Fake
with MockPlatformInterfaceMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
// ignore: undefined_hidden_name
import 'package:flutter/services.dart' hide AssetManifest;
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_fonts/src/google_fonts_base.dart';
Expand All @@ -22,6 +21,13 @@ class MockHttpClient extends Mock implements http.Client {
}
}

class MockAssetManifest extends Mock implements AssetManifest {
@override
List<String> listAssets() {
return ['google_fonts/Foo-BlackItalic.ttf'];
}
}

class FakePathProviderPlatform extends Fake
with MockPlatformInterfaceMixin
implements PathProviderPlatform {
Expand Down Expand Up @@ -59,6 +65,7 @@ void main() {
setUp(() async {
mockHttpClient = MockHttpClient();
httpClient = mockHttpClient;
assetManifest = MockAssetManifest();
GoogleFonts.config.allowRuntimeFetching = true;
when(mockHttpClient.gets(any)).thenAnswer((_) async {
return http.Response(_fakeResponse, 200);
Expand Down
Loading