Error: google_fonts was unable to load font

Viewed 8705

I'm trying to use GoogleFonts to test my UI but I'm getting this strange error error: google_fonts was unable to load font.

Thats occurs with any single font.

This is my setup VsCode Flutter 1.12.13+hf9 Windows 10

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  google_fonts: ^0.4.0

Code

import 'package:google_fonts/google_fonts.dart';
Text('data2', style: GoogleFonts.mcLaren())

Error

I/flutter ( 5069): error: google_fonts was unable to load font McLaren-Regular because the following exception occured I/flutter ( 5069): Exception: Failed to load font with url: https://fonts.gstatic.com/s/a/ca48a5e17b0201057453d49c4271d139e5824b553505ad1c6fbbd7cbbbf4d1dc.ttf

[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows, locale pt-BR)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] Android Studio (not installed)
[√] VS Code, 64-bit edition (version 1.44.0)
[√] Connected device (1 available)

! Doctor found issues in 1 category.
4 Answers

My mistake, I figure out that:

Emulator/device needs internet connectivity.
Google fonts need internet connection on device/emulator.

You need to add Internet permission in the AndroidManifest.xml. <uses-permission android:name="android.permission.INTERNET"/>

There could be few possible reasons for it:

  1. Have you installed the Google Font library using PubSpec Assist ?https://marketplace.visualstudio.com/items?itemName=jeroen-meijer.pubspec-assist. Initially when I installed the plugin using this extension, it did not work (it should work but strangely it did not). So I installed the plugin in the usual way.
  2. You need to restart your app in order for changes to take place. The changes in pubspec.yaml will not reflect on mere Hot Reload / Hot Restart.
  3. You can rebuild the app using flutter clean first.

Removing the app from the device and reinstalling it might solve your problem. It solved for me, when i was facing the same problem.

Related