英文:
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! ? ' (f/o)' : '';
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)
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论