forked from material-foundation/flutter-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom implementations for font data loading.
This adds a new public API, `GoogleFontsLoader`, and a corresponding new instance field `fontLoader` in the global `GoogleFonts.config` class. The new API allows users to hook the loading of fonts into the Flutter engine, which is useful in scenarios where the actual font data is needed for other purposes. The newly added default font loader simply uses Flutter's `FontLoader` as before. Fixes material-foundation#102.
- Loading branch information
1 parent
fb9b4e9
commit a4dc2eb
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flutter/services.dart' show FontLoader; | ||
|
||
/// Abstract base class for implementations that load font data into the Flutter | ||
/// engine. | ||
abstract class GoogleFontsLoader { | ||
/// Loads the given font family and its font data into the Flutter engine, | ||
/// making the font available for use. | ||
Future<void> loadFont(String familyName, Future<ByteData> bytes); | ||
} | ||
|
||
/// The default font loader, using the Flutter default [FontLoader]. | ||
class DefaultGoogleFontsLoader implements GoogleFontsLoader { | ||
@override | ||
Future<void> loadFont(String familyName, Future<ByteData> bytes) async { | ||
final loader = FontLoader(familyName); | ||
loader.addFont(bytes); | ||
await loader.load(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters