Al Walid Ashik
Al Walid Ashik

Reputation: 1779

Invalid value style ((String)) for font -> style in Flutter

For adding custom font style in pubspec.yaml gives

Error detected in pubspec.yaml:
Invalid value Bold ((String)) for font -> style.
Please correct the pubspec.yaml file at /Users/directory/pubspec.yaml

here is the code in pubspec.yaml

  fonts:
    - family: Gilroy
      fonts:
        - asset: fonts/gilroy_bold.ttf
          style: Bold
        - asset: fonts/gilroy_bolditalic.ttf
          weight: 900
        - asset: fonts/gilroy_medium.ttf
          weight: 700

Upvotes: 3

Views: 4538

Answers (3)

Van Philip Panugan
Van Philip Panugan

Reputation: 61

The reason why style: bold does not work is because there is only two constants in Flutter > dart:ui > FontStyle enum, which are:

  • italicconst FontStyle

  • normalconst FontStyle

  • valuesconst List<FontStyle>

Check: https://api.flutter.dev/flutter/dart-ui/FontStyle.html

Upvotes: 4

lsaudon
lsaudon

Reputation: 1458

You want this.

  fonts:
    - family: Gilroy
      fonts:
        - asset: fonts/gilroy_bold.ttf
          weight: 700
        - asset: fonts/gilroy_bolditalic.ttf
          weight: 700
          style: italic
        - asset: fonts/gilroy_medium.ttf
          weight: 500

Upvotes: 5

Umar Calcuttawala
Umar Calcuttawala

Reputation: 331

    fonts:
        - family: Gilroy
          fonts:
            - asset: fonts/gilroy_bold.ttf
              weight: <your_desired_value>  (But must be between 100 to 900)
            - asset: fonts/gilroy_bolditalic.ttf
              weight: 900
            - asset: fonts/gilroy_medium.ttf
              weight: 700

Upvotes: 0

Related Questions