Flutter中的字体->样式无效的值样式((String))

时间:2020-11-06 09:16:37

标签: flutter custom-font

用于在pubspec.yaml中添加自定义字体样式给出

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

这是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

3 个答案:

答案 0 :(得分:0)

你想要这个。

  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

答案 1 :(得分:0)

    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

答案 2 :(得分:-1)

style:bold之所以不起作用,是因为FontStyle中只有两个常量,斜体和普通。

检查: https://api.flutter.dev/flutter/dart-ui/FontStyle-class.html