flutter_glove_box
flutter_glove_box copied to clipboard
How to work with GoogleFonts
I know that font support is limited. Is there any way to configure golden tests to work with google_fonts? At the moment my test outright fails due to Error: google_fonts was unable to load font...
This is primarily an issue with google_fonts, but I was wondering if your team had any remedies for this?
I think this would be a great addition. I have not worked with Google fonts yet but I think adding a package that would add this functionality to the repo but publish it as a stand alone tool so people can choose to add it when using Google fonts.
Hi guys,
google fonts are working with this library. You just have to download the fonts you are using and add them to your assets. The default behavior of the google fonts package is to download the fonts during runtime via http, which is not allowed in widget tests.
There is a description on how to add the fonts to your assets in the google_fonts readme: https://pub.dev/packages/google_fonts#bundling-font-files-in-your-applications-assets
This works fine for me in the goldenTests together with "await loadAppFonts();"
Hope this helps
I don't think I'd say that manually downloading fonts qualifies as "working with this library". The purpose of the google_fonts package is to avoid manually downloading fonts. If we're going to manually download them, then we don't need the google_fonts package.
App can still download it at runtime, but in order to have exact goldens you can supply fonts only in tests. Plus I don't expect fonts to change much over time. That being said - it's a solid workaround
On Sat, May 1, 2021 at 2:52 PM Matt Carroll @.***> wrote:
I don't think I'd say that manually downloading fonts qualifies as "working with this library". The purpose of the google_fonts package is to avoid manually downloading fonts. If we're going to manually download them, then we don't need the google_fonts package.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eBay/flutter_glove_box/issues/87#issuecomment-830699564, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDW7BLDFUSF6T54QX2RSNLTLRZYJANCNFSM4TZKRUVA .
Yes, it's a workaround, but by definition that means there's a problem to work around.
I don't think it's a good idea to make assumptions about the rate that fonts might change. One app will have very different requirements from another.
I think the original goal/request is still 100% valid and it would be great if it were facilitated (whether those changes happen in this lib, or google_fonts, or Flutter itself).
https://pub.dev/packages/google_fonts according to the documentation for google_fonts they recommend downloading the fonts after you settle on the fonts you want for your application. Downloading at runtime is not intended to be a production app production behavior. Additionally I do not think you would want your goldens to suddenly change if the font is updated. You would want to explicitly accept the change to the font.
You could wire up this up to fake downloading the font but you would still need to download the fonts for the tests first.
Downloading fonts and initializing them before tests helps me.
How to download and save fonts: https://pub.dev/packages/google_fonts#bundling-fonts-when-releasing How to initialize fonts:
- Create file
test/flutter_test_config.dart
import 'dart:async';
import 'package:golden_toolkit/golden_toolkit.dart';
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
await loadAppFonts();
return testMain();
}