Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load fonts when running widget tests #439

Closed
1 task done
RishabJaiswal opened this issue Jul 6, 2023 · 10 comments
Closed
1 task done

Unable to load fonts when running widget tests #439

RishabJaiswal opened this issue Jul 6, 2023 · 10 comments
Labels
bug Something isn't working p: google_fonts waiting for developer response The team cannot make further progress on this issue until the original reporter responds

Comments

@RishabJaiswal
Copy link

RishabJaiswal commented Jul 6, 2023

Package

google_fonts

Existing issue?

What happened?

Expected vs actual result:

I don't want to include font files in my release bundle, hence only relying in the downloadable nature of the fonts but the test log is getting polluted throwing exceptions that the test failed to load.

image

Steps to reproduce:

  1. Create a widget that uses downloadable google_font
  2. Do not include font files in assets or google_fonts
  3. Create a widget test for the widget in step
  4. Run the widget test. The exception in above screen shot is thrown.

Using google_fonts: 4.0.3

Relevant log output

Error: google_fonts was unable to load font SourceSansPro-SemiBold because the following exception occurred:
Exception: Failed to load font with url: https://fonts.gstatic.com/s/a/918213748bccf07ee3b20ed95cc824bb329b9b048732700e32c241bba63a029b.ttf

There is likely something wrong with your test. Please see https://github.com/material-foundation/flutter-packages/blob/main/packages/google_fonts/example/test for examples of how to test with google_fonts.
If troubleshooting doesn't solve the problem, please file an issue at https://github.com/material-foundation/flutter-packages/issues/new/choose.

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _Exception was thrown running a test (but after the test had completed):
Exception: Failed to load font with url:
https://fonts.gstatic.com/s/a/918213748bccf07ee3b20ed95cc824bb329b9b048732700e32c241bba63a029b.ttf

When the exception was thrown, this was the stack:
#0      _httpFetchFontAndSaveToDevice (package:google_fonts/src/google_fonts_base.dart:274:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
@RishabJaiswal RishabJaiswal added bug Something isn't working triage Issues that haven't been triaged labels Jul 6, 2023
@BetoMottu
Copy link

we have the same error, using version 4.0.4

image

@guidezpl
Copy link
Collaborator

guidezpl commented Aug 9, 2023

The original issue regards tests (see the README and its links for working test examples).

@BetoMottu if you have end users facing this issue, than your app doesn't seem to have the correct permissions. The error includes a link pointing you to resources to properly set your apps' access to the internet.

@guidezpl guidezpl added waiting for developer response The team cannot make further progress on this issue until the original reporter responds and removed triage Issues that haven't been triaged labels Aug 9, 2023
@BetoMottu
Copy link

@guidezpl, before declaring the problem we check all permissions, as the problem seems to have something to do with connection permission. Our application uses this lib since the beginning of the project a little over 1 year, apparently the problem occurred after the update from version 3.0.1 to 4.0.4, previously we didn't have this problem. Analyzing the issues of this project I found something that is also related to our project, and that could be related to the problem. We used the Poppins font and another report was made with a similar problem: #441

As you can see below, only the source link is available for download, without a link to deal with the problem:

image

We keep getting the error, we are investigating on our side.

@guidezpl
Copy link
Collaborator

@cybex-dev
Copy link

Experiencing the same issue, Android specifically

https://fonts.gstatic.com/s/a/9ecfd020e9cc0b676025df8390c0dc8cc2062523540887dd04bec0ef4d5a449c.ttf is a valid link, so please double check permissions, https://docs.flutter.dev/data-and-backend/networking

According to Data and Backend > Networking,

Android apps must declare their use of the internet in the Android manifest (AndroidManifest.xml )

We have this included and have had for a while however issue persists. Based on affected users, it affects a handful possibly indicating network connectivity issues. I'd still like to contribute this issue to the discussion.
image

@guidezpl
Copy link
Collaborator

@cybex-dev thanks for checking, are there multiple AndroidManifest.xml files?

@cybex-dev
Copy link

@cybex-dev thanks for checking, are there multiple AndroidManifest.xml files?

None extra other than the 3 standard build variation manifests in src/debug, src/main, src/profile all which contain:

<uses-permission android:name="android.permission.INTERNET"/>

@cybex-dev
Copy link

I ended up using the local caching solution by providing desired fonts in the google_fonts/ assets directory, see this solution for details if anyone is interested.

@guidezpl
Copy link
Collaborator

That answer isn't quite right, prefer using https://pub.dev/documentation/google_fonts/latest/google_fonts/GoogleFonts/config.html to disallow internet fetching and rely on local fonts only.

@guidezpl
Copy link
Collaborator

guidezpl commented Feb 26, 2024

Since we have working unit and widget tests in packages/google_fonts/test, I'm considering this issue unreproducible and will therefore close it. If this changes, or if you have an idea for improving the existing tests to cover your case, please reopen this issue. I've also created #560 as a central place to deal with the font fetching issue.

@guidezpl guidezpl closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p: google_fonts waiting for developer response The team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

4 participants