在颤动中格式化文本小部件的部分文本

pra*_*ale 6 flutter

我的文本小部件看起来像Text("Last Active: some location area..").

我可以使用样式更改完整文本的文本样式。但我只是喜欢将 Last active 更改为粗体。Text("<b>Last Active</b> some location area name..")

如果我将 Row 用于单独的文本,它将起作用,但会出现间距问题。

什么是最好的解决方案。并使其大胆是唯一的要求。

谢谢

And*_*sky 12

RichText 是解决方案

RichText(text: TextSpan(children: [
      TextSpan(text: 'Last Active', style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(text: ' some location area name..')
    ]))
Run Code Online (Sandbox Code Playgroud)


Rob*_*bie 9

我在使用Andrey Turkovsky解决方案时遇到问题,文本区域将是空白的。我确实找到了一个稍微替代的解决方案。(我确实想对 Andreys 发表评论,也许他可以解释两者之间的差异,我有兴趣)

  Text.rich(
    TextSpan(
      children: [
        TextSpan(
            text: 'Last Active',
            style: TextStyle(fontWeight: FontWeight.bold)),
        TextSpan(text: ' some location area name..')
      ],
    ),
  )
Run Code Online (Sandbox Code Playgroud)