首页 > 解决方案 > 如何设置嵌入文本的样式?

问题描述

我在下面有一段代码,我想以不同的方式设置文本“From”的样式,即,将其显示为黑色和粗体。它应该保持相同的格式。

谢谢你。

Text("From :" + " " + from, style: GoogleFonts.viga(
              color: Colors.blue[800],
              fontWeight: FontWeight.w500,
              ),  /*TextStyle(color: Colors.blue[800],)*/
            ),

标签: flutter

解决方案


您可以使用RichTextTextSpan类来实现此行为。

RichText(
  text: TextSpan(
    text: 'From:',
    style: TextStyle(color: Colors.black),
    children: <TextSpan>[
      TextSpan(text: ' $from', style: TextStyle(color: Colors.blue[800])),

    ],
  ),
)

你可以在这里阅读更多关于它的信息


推荐阅读