颤振分裂并使特定单词加粗 [英] Flutter split and make specific word bold
本文介绍了颤振分裂并使特定单词加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的字符串@ username,你好吗"我想将@username文本更改为粗体...只是@username而不是整个句子
I have string which is like "Hi @username how are you" I want to change @username text to bold... just @username not whole sentence
示例:您好 @用户名您好
推荐答案
这是一个小功能,可以为您完成此操作,然后返回小部件列表.
This is a small function that would do that for you then returns a list of widgets.
List<Text> _transformWord(String word) {
List<String> name = word.split(' ');
List<Text> textWidgets = [];
for (int i = 0; i < name.length; i++) {
if (name[i].contains('@')) {
Text bold = Text(
name[i] + ' ',
style: TextStyle(
fontWeight: FontWeight.bold,
),
);
textWidgets.add(bold);
} else {
Text normal = Text(
name[i] + ' ',
);
textWidgets.add(normal);
}
}
return textWidgets;
}
您将从行小部件中调用此函数
You would call this function from a row widget
Row(
children: _transformWord(),
),
这篇关于颤振分裂并使特定单词加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文