How to use a custom font style in flutter?

前端 未结 4 739
执笔经年
执笔经年 2021-01-04 09:47

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

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


        
4条回答
  •  温柔的废话
    2021-01-04 10:28

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

    To use the different variations, set a TextStyle

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

    I think thin is FontWeight.w200.

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

提交回复
热议问题