Skip to content

Register a package's own fonts under packages/<self>/#145

Merged
passsy merged 3 commits into
mainfrom
fix/own-package-font-registration
Jun 10, 2026
Merged

Register a package's own fonts under packages/<self>/#145
passsy merged 3 commits into
mainfrom
fix/own-package-font-registration

Conversation

@passsy

@passsy passsy commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Fixes #141

loadAppFonts() registered fonts declared with a bare lib/... asset path (the idiomatic form for a package's own fonts) only under their bare family name. When the same package references those fonts with package: '<self>', Flutter resolves the family to packages/<self>/MyFont at lookup time — a name that was never registered, so Skia fell back to Ahem (empty boxes) even though the bytes were loaded.

This bit Wiredash, which declares Inter/Wirecons with lib/assets/fonts/... paths but sets package: 'wiredash' on its TextStyle/IconData.

Fix

// pubspec.yaml
fonts:
  - family: MyFont
    fonts:
      - asset: lib/fonts/MyFont-Regular.ttf   // bare lib/... path

// referenced in code as:
TextStyle(fontFamily: 'MyFont', package: 'own_package')  // -> packages/own_package/MyFont

Before: only MyFont was registered → packages/own_package/MyFont rendered as Ahem.
After: the test target's package name is read from pubspec.yaml and bare-path fonts are additionally registered as packages/<self>/MyFont, mirroring the existing packages/ asset branch.

This makes the two directions symmetric and matches what Flutter does internally when resolving package: on a TextStyle/IconData.

The app_font template already declares PrivateFont with a bare lib/... path; a new golden test now also resolves it via packages/app_font/PrivateFont so the regression can't sneak back in.

passsy added 3 commits June 10, 2026 11:42
loadAppFonts() registered fonts declared with a bare lib/... asset path
only under their bare family name. When the same package references those
fonts with `package: '<self>'`, Flutter resolves the family to
packages/<self>/MyFont at lookup time, which was never registered, so
Skia fell back to Ahem.

Read the test target's package name from pubspec.yaml and additionally
register bare-path fonts as packages/<self>/MyFont, mirroring the
packages/ asset branch.

Closes #141
These tests spawn a real `flutter test` subprocess that compiles and
runs a drag/tap scenario. On slower CI runners (notably Flutter 3.10)
the cold compile occasionally exceeds the default 30s test timeout,
killing the child process and surfacing as a flaky 'exit code -9'
failure. Give them a 2 minute budget so CI contention no longer trips
the deadline.
@passsy passsy force-pushed the fix/own-package-font-registration branch from 58c1379 to dbd705e Compare June 10, 2026 09:48
@passsy passsy merged commit fccb725 into main Jun 10, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loadAppFonts() doesn't register a package's own fonts under packages/<self>/<family>

1 participant