dart 尽管字体元数据具有准确的权重数,但Flutter自定义字体仅呈现两个权重

cngwdvgl  于 2022-12-20  发布在  Flutter
关注(0)|答案(1)|浏览(144)

我在pubspec.yaml中的导入已经足够标准了,我确实知道pubspec忽略了权重。

fonts:
  - family: Museo_Slab
    fonts:
      - asset: assets/fonts/Museo_Slab/Museo_Slab_100.otf
        weight: 100

      - asset: assets/fonts/Museo_Slab/Museo_Slab_300.otf
        weight: 300

      - asset: assets/fonts/Museo_Slab/Museo_Slab_500.otf
        weight: 500

      - asset: assets/fonts/Museo_Slab/Museo_Slab_700.otf
        weight: 700

      - asset: assets/fonts/Museo_Slab/Museo_Slab_900.otf
        weight: 900

FontBook中的字体元数据显示100、300等的确切数字。渲染时:

Text(
  'Museo Slab 700',
  maxLines: 2,
  overflow: TextOverflow.ellipsis,
  style: TextStyle(
      fontFamily: 'Museo_Slab',
      fontWeight: FontWeight.w700,
      fontSize: 20,
      color: Colors.black),
),

Flutter只拾取了前两个权重,并像这样渲染。
Not great screenshot
本来应该是这样的
Sanity screenshot
我已经检查了字体元数据,并尝试卸载和重新安装字体,但我仍然没有看到正确的权重。

fhg3lkii

fhg3lkii1#

我也面临着同样的问题。我能找到的唯一解决办法是单独定义家庭:

- family: Museo_Slab100
  fonts:
    - asset: assets/fonts/Museo_Slab/Museo_Slab_100.otf

- family: Museo_Slab300
  fonts:
    - asset: assets/fonts/Museo_Slab/Museo_Slab_300.otf

- family: Museo_Slab500
  fonts:
    - asset: assets/fonts/Museo_Slab/Museo_Slab_500.otf

- family: Museo_Slab700
  fonts:
    - asset: assets/fonts/Museo_Slab/Museo_Slab_700.otf

- family: Museo_Slab900
  fonts:
    - asset: assets/fonts/Museo_Slab/Museo_Slab_900.otf

                        const Text(
                          'Museo Slab 100',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontFamily: 'Museo_Slab100',
                              fontSize: 20,
                              color: Colors.black),
                        ),
                        const Text(
                          'Museo Slab 300',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontFamily: 'Museo_Slab300',
                              fontSize: 20,
                              color: Colors.black),
                        ),
                        const Text(
                          'Museo Slab 500',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontFamily: 'Museo_Slab500',
                              fontSize: 20,
                              color: Colors.black),
                        ),
                        const Text(
                          'Museo Slab 700',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontFamily: 'Museo_Slab700',
                              fontSize: 20,
                              color: Colors.black),
                        ),
                        const Text(
                          'Museo Slab 900',
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontFamily: 'Museo_Slab900',
                              fontSize: 20,
                              color: Colors.black),
                        ),

相关问题