You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then I use it in flutter. But in app I see default 'Roboto' fonts everywhere.
It's stated in the cookbook: https://docs.flutter.dev/cookbook/design/package-fonts#declare-the-font-assets - "please declare all the package fonts".
Indeed, if I declare all the package fonts in the head app project, it finds it:
But that's not what I want! I don't want to force user to duplicate all the fonts in his pubspec. I already declared fonts in my package.
I want him to just download the package and use fonts (using generated font constants).
I believe it's an omitment of Dart: it can't transitively see fonts declared in the inner package until I explicitly add them in the pubspec.
If it's impossible, I suggest using some shorthand syntax like
fonts:
import packages/mts_granat # imports all fonts from its pubspec
I don't want to force user to duplicate all the fonts in his pubspec. I already declared fonts in my package.
@subzero911 As my understanding, the guideline from the docs doesn't work for you and you are declaring fonts twice (in package and project pubspec.yaml files), right?
As my understanding, the guideline from the docs doesn't work for you and you are declaring fonts twice (in package and project pubspec.yaml files), right?
Not exactly. The guideline describes the situation when I just added fonts into the package. And it offers to reference them in a project's pubspec with packages/awesome_pkg/... prefix.
In my case, I declare fonts in a package pubspec.
Expected behaviour: project can use these fonts if I included a package, because fonts are already declared in it.
Actual behaviour: project "can't see" these fonts until I declare these fonts in a project's pubspec too.
Proposal: add a simple way to declare package fonts in a project with 1 line of code:
PS C:\Users\subze> flutter doctor -v
[√] Flutter (Channel stable, 3.7.0, on Microsoft Windows [Version 10.0.19045.2486], locale ru-RU)
• Flutter version 3.7.0 on channel stable at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (8 days ago), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1
[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at D:\Android_SDK
• Platform android-33, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.5)
• Visual Studio at D:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.31729.503
• Windows 10 SDK version 10.0.20348.0
[√] Android Studio (version 2021.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
[√] IntelliJ IDEA Community Edition (version 2020.1)
• IntelliJ at D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.3
• Flutter plugin version 45.1.3
• Dart plugin version 201.7223.43
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.2486]
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.120
• Edge (web) • edge • web-javascript • Microsoft Edge 99.0.1150.55
[√] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
@subzero911
What I mean is similar to what you are describing (you are having to declare fonts twice on both package and project to be able to use fonts)
However, it works as expected when adding package attribute to TextStyle, like this:
Text(
'Font example',
style: TextStyle(
// font from the package
fontFamily: 'Ginger',
fontSize: 44,
package: 'awesome_fonts_collection'
),
)
Also, you don't need to declare font in project's pubspec.yaml anymore. Just try this and see the result.
Wow, it actually works! Thank you, Mr. @huycozy, sir, I think it solved my problem.
I honestly didn't know about this package: parameter. It isn't mentioned in TextStyle docs neither in any articles.
It exists in a "Custom Fonts" section but does not exists in a Class properties list.
Okay, I also see that package parameter exists in a ThemeData and TextTheme too.
And it applies the custom fonts to all the children TextStyles. That should be enough for app styling.
And it's not documented as well for some reason.
@huycozy I recommend to reopen an issue with a need_documentation label.
And I also found, that ThemeData copyWith does not contain the package parameter.
So if I declared themes in a separate package, I cannot add a fonts package link to it in my app. Because I cannot do: lightTheme: externalThemeLight.copyWith(package: 'awesome_fonts')
@subzero911 I see, there is no package parameter in Class properties from the document. To help the issue can be transparent and clear, would you mind filing another issue for this?
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
huycozy commentedon Jan 31, 2023
@subzero911 As my understanding, the guideline from the docs doesn't work for you and you are declaring fonts twice (in package and project
pubspec.yamlfiles), right?Can you provide a completed and minimal reproducible code sample so that we may verify this? Also, please provide the output of
flutter doctor -vas well.Thank you!
subzero911 commentedon Jan 31, 2023
Not exactly. The guideline describes the situation when I just added fonts into the package. And it offers to reference them in a project's pubspec with
packages/awesome_pkg/...prefix.In my case, I declare fonts in a package pubspec.
Expected behaviour: project can use these fonts if I included a package, because fonts are already declared in it.
Actual behaviour: project "can't see" these fonts until I declare these fonts in a project's pubspec too.
Proposal: add a simple way to declare package fonts in a project with 1 line of code:
subzero911 commentedon Jan 31, 2023
I prepared a minimal example and commented it. Check please:
https://github.com/subzero911/transitive_fonts_demo
flutter doctor
huycozy commentedon Feb 1, 2023
@subzero911
What I mean is similar to what you are describing (you are having to declare fonts twice on both package and project to be able to use fonts)
However, it works as expected when adding
packageattribute toTextStyle, like this:Also, you don't need to declare font in project's pubspec.yaml anymore. Just try this and see the result.
subzero911 commentedon Feb 1, 2023
Wow, it actually works! Thank you, Mr. @huycozy, sir, I think it solved my problem.
I honestly didn't know about this
package:parameter. It isn't mentioned in TextStyle docs neither in any articles.huycozy commentedon Feb 1, 2023
Glad it works for you. You may want to check the TextStyle document and scroll to
Custom Fontssection.Closing the issue as solved.
subzero911 commentedon Feb 1, 2023
It exists in a "Custom Fonts" section but does not exists in a Class properties list.
Okay, I also see that
packageparameter exists in a ThemeData and TextTheme too.And it applies the custom fonts to all the children TextStyles. That should be enough for app styling.
And it's not documented as well for some reason.
@huycozy I recommend to reopen an issue with a
need_documentationlabel.subzero911 commentedon Feb 1, 2023
And I also found, that ThemeData
copyWithdoes not contain thepackageparameter.So if I declared themes in a separate package, I cannot add a fonts package link to it in my app. Because I cannot do:
lightTheme: externalThemeLight.copyWith(package: 'awesome_fonts')huycozy commentedon Feb 2, 2023
@subzero911 I see, there is no
packageparameter in Class properties from the document. To help the issue can be transparent and clear, would you mind filing another issue for this?github-actions commentedon Mar 3, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.