flutter_glove_box icon indicating copy to clipboard operation
flutter_glove_box copied to clipboard

How to work with GoogleFonts

Open matthew-carroll opened this issue 5 years ago • 8 comments

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?

matthew-carroll avatar Nov 18 '20 01:11 matthew-carroll

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.

fatherOfLegends avatar Nov 18 '20 02:11 fatherOfLegends

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

NikoBoerger avatar May 01 '21 10:05 NikoBoerger

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.

matthew-carroll avatar May 01 '21 21:05 matthew-carroll

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 .

mZadorskii avatar May 01 '21 22:05 mZadorskii

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).

matthew-carroll avatar May 01 '21 22:05 matthew-carroll

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.

fatherOfLegends avatar May 01 '21 23:05 fatherOfLegends

You could wire up this up to fake downloading the font but you would still need to download the fonts for the tests first.

fatherOfLegends avatar May 01 '21 23:05 fatherOfLegends

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();
}

InAnadea avatar Jul 25 '23 08:07 InAnadea