String 颤振分裂,使具体的字加粗
我有一根像 “嗨@username你好吗?” 我想将@username文本更改为粗体。。。只是@username,而不是整个句子String 颤振分裂,使具体的字加粗,string,flutter,uiview,flutter-test,String,Flutter,Uiview,Flutter Test,我有一根像 “嗨@username你好吗?” 我想将@username文本更改为粗体。。。只是@username,而不是整个句子 示例:“嗨@username你好使用flift文本span Text _myText; /*set _myText.text to whatever text you want */ RichText( text: TextSpan( text: 'Hi', style: DefaultTextStyle.of(context).style,
示例:“嗨@username你好使用flift文本span
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')
],
),
)
Text\u myText;
/*将_myText.text设置为所需的任何文本*/
RichText(
text:TextSpan(
文字:“嗨”,
样式:DefaultTextStyle.of(context.style),
儿童:[
TextSpan(text:_myText.text,style:TextStyle(fontwweight:fontwweight.bold)),
TextSpan(文本:“你好吗”)
],
),
)
这是一个小函数,可以为您执行此操作,然后返回小部件列表
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;
}
这回答了你的问题吗?@jbarat-nope,实际上我有一个列表,列表中是,msg,userid被抛出,在msg中我想让上面的内容为我工作,谢谢you@HadiHaidar不客气!
Row(
children: _transformWord(),
),