温馨提示×

Flutter中FontWeight属性怎样设置

小樊
81
2024-07-01 11:14:39
栏目: 编程语言

在Flutter中,可以使用FontWeight属性来设置文本的粗细程度。FontWeight属性接受一个FontWeight枚举类型的值,包括以下几种常用的值:

  1. FontWeight.w100 - 超轻
  2. FontWeight.w200 - 轻
  3. FontWeight.w300 - 较轻
  4. FontWeight.w400 - 普通
  5. FontWeight.w500 - 中等
  6. FontWeight.w600 - 较粗
  7. FontWeight.w700 - 粗
  8. FontWeight.w800 - 较粗
  9. FontWeight.w900 - 超粗

例如,如果要将文本设置为粗体字体,可以将fontWeight属性设置为FontWeight.bold,如下所示:

Text(
  'Hello, World!',
  style: TextStyle(
    fontWeight: FontWeight.bold,
  ),
),

除了使用上述常用的值外,也可以通过FontWeight的静态方法来创建自定义的粗细程度,例如:

FontWeight customFontWeight = FontWeight.w500 + 100;
Text(
  'Hello, World!',
  style: TextStyle(
    fontWeight: customFontWeight,
  ),
),

0