溫馨提示×

Flutter中FontWeight屬性怎樣設(shè)置

小樊
156
2024-07-01 11:14:39
欄目: 編程語言

在Flutter中,可以使用FontWeight屬性來設(shè)置文本的粗細(xì)程度。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 - 超粗

例如,如果要將文本設(shè)置為粗體字體,可以將fontWeight屬性設(shè)置為FontWeight.bold,如下所示:

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

除了使用上述常用的值外,也可以通過FontWeight的靜態(tài)方法來創(chuàng)建自定義的粗細(xì)程度,例如:

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

0