【问题标题】:fomat partial text of Text widget in flutter在颤动中格式化文本小部件的部分文本
【发布时间】:2018-10-16 10:57:52
【问题描述】:

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

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

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

对此最好的解决方案是什么。并且使其粗体是唯一的要求。

谢谢

【问题讨论】:

    标签: flutter


    【解决方案1】:

    富文本是解决方案

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 这应该是公认的解决方案。 @Andrey Turkovsky 的解决方案在这里显示为空白。但这个解决方案就像魅力一样!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 2019-03-19
      • 1970-01-01
      • 2021-08-25
      • 2020-09-10
      相关资源
      最近更新 更多