在Flutter中以不同的颜色显示几个单词 [英] Display a few words in different colors in Flutter
本文介绍了在Flutter中以不同的颜色显示几个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个应用程序,该应用程序以颤抖的方式显示几个不同颜色的单词.
I am writing an application which shows a few words in different colors in flutter.
我尝试使用插件flutter_html_view加载HTML文件,但该插件不支持样式(内联).我也尝试使用markdown.
I tried to load HTML files using the plugin flutter_html_view but that one doesn't support styles(inline). I also tried to use 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)),
],
),
);
这篇关于在Flutter中以不同的颜色显示几个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文