Skip to content

Configured font weights do not align with custom font #50216

Description

@Schoonology

I have a typeface with multiple weights I want access to, and font files for each of these weights. I've configured pubspec.yaml with those weights, but they are not used when the identical FontWeight is used in a TextStyle.

pubspec:

  fonts:
    - family: Chivo
      fonts:
        - asset: assets/fonts/Chivo-Regular.ttf
        - asset: assets/fonts/Chivo-Italic.ttf
          style: italic
        - asset: assets/fonts/Chivo-Light.ttf
          weight: 200
        - asset: assets/fonts/Chivo-LightItalic.ttf
          weight: 200
          style: italic
        - asset: assets/fonts/Chivo-Bold.ttf
          weight: 700
        - asset: assets/fonts/Chivo-BoldItalic.ttf
          style: italic
          weight: 700
        - asset: assets/fonts/Chivo-Black.ttf
          weight: 900
        - asset: assets/fonts/Chivo-BlackItalic.ttf
          weight: 900
          style: italic

If I then used FontWeight.bold in a TextStyle, the 900 weight is used instead. This does not line up with the documentation on using custom fonts here: https://flutter.dev/docs/cookbook/design/fonts#pubspecyaml-option-definitions

Should the documentation be updated, or is this an issue that should be fixed in the framework?

There is a workaround: two fonts. I configured one font with the "common" weights (400/700), and a second with the "extreme" weights (200/900), treated as 400/700:

  fonts:
    - family: Chivo
      fonts:
        - asset: assets/fonts/Chivo-Regular.ttf
        - asset: assets/fonts/Chivo-Italic.ttf
          style: italic
        - asset: assets/fonts/Chivo-Bold.ttf
          weight: 700
        - asset: assets/fonts/Chivo-BoldItalic.ttf
          style: italic
          weight: 700
    - family: 'Chivo Extreme'
      fonts:
        - asset: assets/fonts/Chivo-Light.ttf
        - asset: assets/fonts/Chivo-LightItalic.ttf
          style: italic
        - asset: assets/fonts/Chivo-Black.ttf
          weight: 700
        - asset: assets/fonts/Chivo-BlackItalic.ttf
          weight: 700
          style: italic

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: assetsPackaging, accessing, or using assetsa: typographyText rendering, possibly libtxtd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions