Flutter 如何在flatter中改变句子中单个单词的颜色
//如何仅更改绿色的“This one”您可以使用Flutter 如何在flatter中改变句子中单个单词的颜色,flutter,dart,Flutter,Dart,//如何仅更改绿色的“This one”您可以使用RichText小部件来实现此结果 您可以学习了解有关此小部件的更多信息 下面是来自同一链接的示例code RichText( text:TextSpan( 文字:“你好”, 样式:DefaultTextStyle.of(context.style), 儿童:[ TextSpan(text:'bold',style:TextStyle(fontwweight:fontwweight.bold)), TextSpan(text:'world!'),
RichText
小部件来实现此结果
您可以学习了解有关此小部件的更多信息
下面是来自同一链接的示例code
RichText(
text:TextSpan(
文字:“你好”,
样式:DefaultTextStyle.of(context.style),
儿童:[
TextSpan(text:'bold',style:TextStyle(fontwweight:fontwweight.bold)),
TextSpan(text:'world!'),
],
),
)
您可以使用RichText
小部件来实现此结果
您可以学习了解有关此小部件的更多信息
下面是来自同一链接的示例code
RichText(
text:TextSpan(
文字:“你好”,
样式:DefaultTextStyle.of(context.style),
儿童:[
TextSpan(text:'bold',style:TextStyle(fontwweight:fontwweight.bold)),
TextSpan(text:'world!'),
],
),
)
Text(
"This is the sentence and "This one" have to be in different color",
style:TextStyle (
color: Colors.green
),
),
RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
)