代码之家  ›  专栏  ›  技术社区  ›  Morez

如何在Flutter中设置文本的一部分样式?

  •  -1
  • Morez  · 技术社区  · 6 年前

    我有一个 Text widget和我想成为它的一部分 bold . 我该怎么做?

    例子: Text("Required interests: Music, Guitar")

    1 回复  |  直到 6 年前
        1
  •  1
  •   Pedro Massango    6 年前

    你可以使用 Text.rich() 为了达到这个目的。

    Text.rich(
      TextSpan(
        text: 'Required interests: ',
        style: TextStyle(fontWeight: FontWeight.bold),
        children: <TextSpan>[
          TextSpan(text: 'Music, Guitar',
            style: TextStyle(fontWeight: FontWeight.normal),
          )
        ]
      ),
    );
    

    children TextSpan 它将使用父级的样式。