Skip to content

fix: remove TextStyle.package to allow copyWith to change the font#1074

Open
adil192 wants to merge 3 commits intoubuntu:mainfrom
adil192:fix/allow-changing-font
Open

fix: remove TextStyle.package to allow copyWith to change the font#1074
adil192 wants to merge 3 commits intoubuntu:mainfrom
adil192:fix/allow-changing-font

Conversation

@adil192
Copy link
Copy Markdown
Contributor

@adil192 adil192 commented Apr 4, 2026

This package's use of TextStyle.package causes problems when apps don't want to use the bundled Ubuntu font.

Problem

The ideal approach to change the font would be something like

textStyle = textStyle.copyWith(fontFamily: 'MyNonYaruFont', package: null);

But the implementation of copyWith cannot remove textStyle.package, leading to the new fontFamily being packages/yaru/MyNonYaruFont.

Users of this package currently need to use workarounds like:

  1. Make a function similar to copyWith that explicitly removes the package field:
    🔗
    But not only is this verbose, but it's likely to break in time as new fields are added to TextStyle.

  2. Ditch Yaru's TextTheme completely, and use the default Flutter TextTheme:
    🔗
    But of course, we then lose Yaru's TextTheme :(.
    Also see How to change font family and font weight #905.

Solution

This PR simply replaces TextStyle(fontFamily: 'Ubuntu', package: 'yaru') with TextStyle(fontFamily: 'packages/yaru/Ubuntu') which is functionally identical except resolving the issue stated above.
This lets apps choose their own fonts without messy boilerplate.

Unit tests have been added for this problem.

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.

1 participant