首页 > 解决方案 > 用于颤振的 Google 字体包无法在发布模式下加载字体

问题描述

我在我的颤振应用程序
https://pub.dev/packages/google_fonts中使用了 Google 字体包

该应用程序在调试模式下运行良好,字体加载没有任何问题。

但是,当我在发布模式下构建和运行应用程序时,字体无法加载。大多数情况下,应用程序会崩溃,有时会加载默认的 Roboto 字体。

GitHub 上存在一些问题,但其中任何一个都不能解决我的问题。我尝试清理构建文件夹,重新检查pubspec.yaml文件,检查google_fonts包版本,验证互联网连接,甚至重新创建项目。但没有什么能解决问题。

版本:

google_fonts: ^1.1.0

flutter run --release我在使用命令运行应用程序时收到此错误日志
这是我收到的错误:

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

标签: flutterflutter-dependencies

解决方案


这个错误可能有很多原因,但我认为这两个之一是这种情况:

  1. 如果它只发生在 android 上,那么也许你没有将它添加<uses-permission android:name="android.permission.INTERNET" />到你的清单文件中。
  2. 您所在的国家/地区禁止此服务

推荐阅读