改变Flutter中字符串的颜色。

huangapple go评论133阅读模式
英文:

Changing the color of string Flutter

问题

你可以通过以下方式来设置字符串 "followOnLabel" 的颜色或文本样式:

final String followOnLabel = inningScore.followOn! ? '<span style="color: your_color_here">(f/o)</span>' : '<span style="color: your_color_here"></span>';

请将 "your_color_here" 替换为你想要的颜色值。这将使用 HTML 标记来为字符串添加颜色样式。

英文:

I am defining a string and now I want to set my string a color, please show how do I do that with my code

  final String followOnLabel = inningScore.followOn! ? &#39; (f/o)&#39; : &#39;&#39;;

I want to set my string followOnLabel color or textstyle. Thank you in advance.

答案1

得分: 2

Strings are text. They don't have colors. Widgets have colors. To give a Text widget a red text you could write this for example:

Text(followOnLabel , style: const TextStyle(color: Colors.red))
英文:

Strings are text. They don't have colors. Widgets have colors. To give a Text widget a red text you could write this for example:

Text(followOnLabel , style: const TextStyle(color: Colors.red))

答案2

得分: 0

根据我的理解,您想根据条件更改字符串的颜色。如果是的话,以下代码将帮助您满足您的要求。

Text(
  followOnLabel,
  style: TextStyle(
    fontFamily: /*Font Family*/,
    color: inningScore.followOn! ? Colors.yellow : Colors.red
  )
)
英文:

@SaDev As I understand, do you want to change the colour of your string depending on the condition? If yes then the below code will help you to meet your requirements.

Text(
 followOnLabel,
 style: TextStyle(
     fontFamily: /*Font Family*/,
     color: inningScore.followOn! ? Colors.yellow : Colors.red)
)

huangapple
  • 本文由 发表于 2023年3月15日 18:07:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定