将单词包装在TextSpan中,并分配
style属性以更改文本外观,并使用RichText代替
Text
> RichText(> text: TextSpan(> text: 'Hello ',> style: DefaultTextStyle.of(context).style,> children: <TextSpan>[>TextSpan(text: 'bold', style: TextStyle(fontWeight:> FontWeight.bold)),>TextSpan(text: ' world!'),> ],> ),> )
或使用
Text.rich构造函数https://docs.flutter.io/flutter/widgets/Text-
class.html
>> const Text.rich(> TextSpan(> text: 'Hello', // default text style> children: <TextSpan>[>TextSpan(text: ' beautiful ', style: TextStyle(fontStyle:> FontStyle.italic)),>TextSpan(text: 'world', style: TextStyle(fontWeight:> FontWeight.bold)),> ],> ),> )>



