本文介绍了如何在Flutter中使用自定义字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在pubspec.yaml上设置了以下代码:

I have already set on my pubspec.yaml the following code:

fonts:
- family: Roboto
  fonts:
    - asset: fonts/Roboto-Light.ttf
    - asset: fonts/Roboto-Thin.ttf
    - asset: fonts/Roboto-Italic.ttf

但是我不知道使用例如Roboto的样式 Roboto-Light.ttf在我的小部件中。我试过了:

But I don't know to use, for example, the style "Roboto-Light.ttf" from Roboto in my widget. I tried this:

new ListTile(
          title: new Text(
            "Home",
            style: new TextStyle(
              fontFamily: "Roboto",
              fontSize: 60.0,
            ),
          ),
        ),

我不知道如何访问样式 Roboto-Light.ttf。

I don't know how to access the style "Roboto-Light.ttf". How to do this?

谢谢!

推荐答案

Roboto是材料样式的默认字体,无需在pubspec.yaml中添加它。

Roboto is the default font of the Material style, there is no need to add it in pubspec.yaml.

要使用不同的变体,请设置 TextStyle

To use the different variations, set a TextStyle

Text(
  'Home',
  style: TextStyle(
    fontWeight: FontWeight.w300, // light
    fontStyle: FontStyle.italic, // italic
  ),
);

我认为瘦的是 FontWeight.w200

相应样式的字体重量在样式部分中提到。 .com / specimen / Source + Sans + Pro?query = source%20sans rel = nofollow noreferrer> GoogleFonts 网站。

The FontWeights for the corresponding styles are mentioned in the styles section of the particular font in GoogleFonts website.

这篇关于如何在Flutter中使用自定义字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:46