string - Flutter拆分并使特定单词加粗
问题描述
我有类似“Hi @username how are you”的字符串 我想将@username 文本更改为粗体......只是@username 不是整个句子
示例:“嗨@username你好吗
解决方案
使用颤振的TextSpan
Text _myText;
/*set _myText.text to whatever text you want */
RichText(
text: TextSpan(
text: 'Hi',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: _myText.text, style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: 'how are you')
],
),
)
推荐阅读
- python - python dicts - 将现有dict上的值从列表转换为集合
- node.js - nodejs - GraphicMagick - 在框架中添加图像以创建另一个图像
- apache - 如何将 .dat 类型添加到 apache mime.types?
- python - 蟒蛇提示中的pygame
- microsoft-graph-api - 用户日历可能存在哪些 Microsoft 图形订阅限制
- sql - 将 varchar 转换为日期 PostgreSQL
- flutter - 如何在颤动中将图像添加到任何形状?
- reactjs - React/Redux,使用 mapDispatchToProps 更新存储
- javascript - 从给定数组创建一个新数组,其中每个元素的长度比前一个元素多一个,使用 Javascript
- android - 如何在 EWS Android 中使用现代身份验证而不是基本身份验证