Reputation: 1135
I have used the Google fonts package in my flutter application
https://pub.dev/packages/google_fonts
The app runs fine on debug mode and the fonts load without any issue.
But, however, when I build and run the application in release mode, the fonts fail to load. Most of the time the app crashes and sometimes the default Roboto font is loaded.
There are some issues open on GitHub but any of that doesn't fix my issue.
I tried cleaning the build folder, rechecked pubspec.yaml
file, checked the google_fonts
package version, verified internet connectivity, and even recreated the project. But nothing solved the issue.
version:
google_fonts: ^1.1.0
I got this error log while running the app using flutter run --release
command
Here's the error I got:
I/flutter (17872): Error: google_fonts was unable to load font Montserrat-SemiBold because the following exception occured:
I/flutter (17872): Exception: Failed to load font with url: https://fonts.gstatic.com/s/a/5f82f6e55db43e905c6ab9d04395566b243c41798d6a53545ffbd10ed6c424c4.ttf
I/flutter (17872): Error: google_fonts was unable to load font Montserrat-Medium because the following exception occured:
I/flutter (17872): Exception: Failed to load font with url: https://fonts.gstatic.com/s/a/cec0f6e0bfbfaa352eb189f0eb220916dd278b02aaf824be87055ba5cc38d58b.ttf
I/flutter (17872): Error: google_fonts was unable to load font Montserrat-Regular because the following exception occured:
I/flutter (17872): Exception: Failed to load font with url: https://fonts.gstatic.com/s/a/470e93c06a9fffa6851375f54047917a9d774ed6027d9f044cd1bc8d4cd5630b.ttf
Upvotes: 7
Views: 7885
Reputation: 24920
Google Fonts
are fetched from the internet in the runtime. So for this to work you need to have active internet connection.
To overcome this,You can download the font from google font
and make it available in the asset folder
i.e offline
and change the code from
// Online Code
Text(
'This is hammersmithOne from Google Font'
style: GoogleFonts.hammersmithOne(),
),
to
// Offline Code
Text(
'This is hammersmithOne from Google Font',
style: TextStyle(fontFamily: 'hammersmithOne') // This is loaded from assets
),
For futher reference refer this article.
Upvotes: 2
Reputation: 9019
This error can have many reasons but I think one of these two is the case:
<uses-permission android:name="android.permission.INTERNET" />
to your manifest file.Upvotes: 6