使用谷歌字体我没有问题,无法正确显示字体粗细。但是,一旦我使用自定义字体,我就会遇到麻烦。我正在使用sofia pro
字体,并将这些字体放入我的资源文件夹中,并由pubspc.yaml
进行了如下设置:
fonts:
- family: SofiaPro
fonts:
- asset: assets/fonts/SofiaProUltraLight.ttf
weight: 200
- asset: assets/fonts/SofiaProLight.ttf
weight: 300
- asset: assets/fonts/SofiaProRegular.ttf
weight: 400
- asset: assets/fonts/SofiaProMedium.ttf
weight: 500
- asset: assets/fonts/SofiaProSemiBold.ttf
weight: 600
- asset: assets/fonts/SofiaProBold.ttf
weight: 700
- asset: assets/fonts/SofiaProBlack.ttf
weight: 900
- family: SofiaProRegular
fonts:
- asset: assets/fonts/SofiaProRegular.ttf
weight: 400
然后我用两种方式引用字体:一次是在其字体家族中没有其他权重的位置,另一种是在其他权重列表中的位置。
Container(
height: height,
child: Center(
child: Text(
"This text has weight w400",
style: TextStyle(fontFamily: 'SofiaPro', fontSize: size, fontWeight: FontWeight.w400),
)),
),
Container(
height: height,
child: Center(
child: Text(
"This text has weight w400",
style: TextStyle(fontFamily: 'SofiaProRegular', fontSize: size, fontWeight: FontWeight.w400),
)),
),
因此,唯一的区别是我所指的字体系列,但显示的文本仅针对其本身属于一个系列的字体正确显示。对于另一个字体,我得到列表中第一个字体的粗细。不确定我在这里缺少什么。
答案 0 :(得分:0)
您提供的字体中可能根本没有字体家族 SofiaProRegular 。
请注意,您同时为 SofiaPro 和 SofiaProRegular 系列添加了assets/fonts/SofiaProRegular.ttf
。
如果要在两个字体系列中使用相同的字体,请尝试以不同的名称复制字体文件。