在Flutter中以不同的颜色显示几个单词
问题内容:
我正在编写一个应用程序,该应用程序会以不同的颜色显示几个单词。
我尝试使用插件flutter_html_view加载HTML文件,但该插件不支持样式(内联)。我也尝试使用markdown。
我该如何实现?
问题答案:
使用RichText类
var text = new RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(text: 'Hello'),
new TextSpan(text: 'World', style: new TextStyle(fontWeight: FontWeight.bold)),
],
),
);