android-studio - 如何格式化(粗体)文本中的单词?
问题描述
在下面的代码中,我想将“$_counter”的值加粗。如何做到这一点?
new Text(
'You have pushed the button $_counter time${_counter > 1
? 's'
: ''}',
style: new TextStyle(fontSize: fontSize),
textAlign: TextAlign.center,
),
我希望输出是这样的:
您已按下按钮2次
解决方案
你必须使用RichTextfor
它
new RichText(
textAlign: TextAlign.center,
text: new TextSpan(
style: TextStyle(color: Colors.black),
children: <TextSpan>[
new TextSpan(text: 'You have pushed the button '),
new TextSpan(text: '$_counter', style: new TextStyle(fontWeight: FontWeight.bold)),
new TextSpan(text: ' time!'),
],
),
)
推荐阅读
- python - 如何在 Python 中将换行符写入 UTF-16 BE 中的文件?
- angular - 在角度路由器链接路径中使用静态变量
- python-3.x - 我有一个包含两部分的文本文件。我想将两个部分分成两个列表。(蟒蛇帮助)
- mysql - 事务 MYSQL LARAVEL
- janusgraph - Janusgraph:无法使用 cql 后端打开图形
- c - 多维数组的形式参数
- c++ - 我刚刚开始学习使用 C++ 的链表。我正在尝试使用向量创建一个链表。为什么这段代码有问题?
- python - Python中自恋数字检查中的意外输出
- c# - 如何防止最终用户通过 C#/.NET 中的过度发布攻击通过其主键修改对象?
- javascript - html2canvas - 错误:元素未附加到文档