Skip to content
Discussion options

You must be logged in to vote

I found a solution:

Add font as asset and change pubspec.yaml:

fonts:
    - family: Ahem
      fonts:
        - asset: assets/fonts/ahem.ttf

In your test:

  bool isTestRunning;

  Future<void> setUpAll() async {
    isTestRunning = true;

    // Explicitly load the font.
    final fontData = await rootBundle.load("assets/fonts/ahem.ttf");
    final fontLoader = FontLoader("Ahem");
    fontLoader.addFont(Future.value(fontData));
    await fontLoader.load();
  }

Wherever the font is set in the application do something like:

  font = isTestRunning ? TextStyle(fontFamily: "Ahem") : myRegularFont;

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robkri
Comment options

Answer selected by robkri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant