【问题标题】:Invalid value style ((String)) for font -> style in FlutterFlutter中字体->样式的值样式((String))无效
【发布时间】:2020-11-06 09:16:37
【问题描述】:

用于在 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

【问题讨论】:

标签: flutter custom-font


【解决方案1】:

你想要这个。

  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

【讨论】:

  • 这是不可能的 不再写粗体。
【解决方案2】:
    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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-01-29
      • 2020-05-17
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2017-12-20
      • 1970-01-01
      相关资源
      最近更新 更多