@@ -94,7 +94,12 @@ TextStyle googleFontsTextStyle({
9494 fontUrl: fonts[matchedVariant],
9595 );
9696
97- loadFontIfNecessary (descriptor);
97+ try {
98+ loadFontIfNecessary (descriptor);
99+ } catch (e) {
100+ final fontName = descriptor.familyWithVariant.toApiFilenamePrefix ();
101+ print ('error: google_fonts was unable to load font $fontName \n $e ' );
102+ }
98103
99104 return textStyle.copyWith (
100105 fontFamily: familyWithVariant.toString (),
@@ -121,40 +126,34 @@ Future<void> loadFontIfNecessary(GoogleFontsDescriptor descriptor) async {
121126
122127 Future <ByteData > byteData;
123128
124- try {
125- // Check if this font can be loaded by the pre-bundled assets.
126- final assetManifestJson = await _loadAssetManifestJson ();
127- final assetPath = getFamilyWithVariantManifestPath (
128- descriptor.familyWithVariant,
129- assetManifestJson,
130- );
131- if (assetPath != '' ) {
132- byteData = rootBundle.load (assetPath);
133- }
134- if (await byteData != null ) {
135- return loadFontByteData (familyWithVariantString, byteData);
136- }
137-
138- // Check if this font can be loaded from the device file system.
139- if (! kIsWeb) {
140- byteData = _loadFontFromDeviceFileSystem (familyWithVariantString);
141- }
142- if (await byteData != null ) {
143- return loadFontByteData (familyWithVariantString, byteData);
144- }
129+ // Check if this font can be loaded by the pre-bundled assets.
130+ final assetManifestJson = await _loadAssetManifestJson ();
131+ final assetPath = getFamilyWithVariantManifestPath (
132+ descriptor.familyWithVariant,
133+ assetManifestJson,
134+ );
135+ if (assetPath != '' ) {
136+ byteData = rootBundle.load (assetPath);
137+ }
138+ if (await byteData != null ) {
139+ return loadFontByteData (familyWithVariantString, byteData);
140+ }
145141
146- // Attempt to load this font via http.
147- byteData = _httpFetchFontAndSaveToDevice (
148- familyWithVariantString,
149- descriptor.fontUrl,
150- );
151- if (await byteData != null ) {
152- return loadFontByteData (familyWithVariantString, byteData);
153- }
154- } catch (e) {
155- final fontName = descriptor.familyWithVariant.toApiFilenamePrefix ();
156- throw Exception ('google_fonts was unable to load font $fontName \n $e ' );
142+ // Check if this font can be loaded from the device file system.
143+ if (! kIsWeb) {
144+ byteData = _loadFontFromDeviceFileSystem (familyWithVariantString);
145+ }
146+ if (await byteData != null ) {
147+ return loadFontByteData (familyWithVariantString, byteData);
157148 }
149+
150+ // Attempt to load this font via http.
151+ byteData = _httpFetchFontAndSaveToDevice (
152+ familyWithVariantString,
153+ descriptor.fontUrl,
154+ );
155+ await byteData;
156+ return loadFontByteData (familyWithVariantString, byteData);
158157}
159158
160159/// Loads a font with [FontLoader] , given its name and byte-representation.
0 commit comments