Flutter:仅在传递给文本小部件之前,才可以在字符串中格式化(粗体,斜体等)吗? [英] Flutter: Is it possible to format (bold, italicize, etc) with-in the string only before passing to the text widget?

查看:100
本文介绍了Flutter:仅在传递给文本小部件之前,才可以在字符串中格式化(粗体,斜体等)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

String desc = "<bold>Hello<bold> World";
new Text(desc);


推荐答案

您可以使用 flutter_html_view 软件包。

字符串html ='< bold> Hello< bold>世界';

new HtmlTextView(data:html);

如果您只想使用其他样式,可以将 RichText 小部件与 TextSpans 例如

If you just want different styles you can use a RichText widget with TextSpans like this.

new RichText( text: new TextSpan(text: 'Hello ', style: DefaultTextStyle.of(context).style, children:          
<TextSpan>[
new TextSpan(text: 'bold', style: new TextStyle(fontWeight: FontWeight.bold)), 
new TextSpan(text: ' world!'), 
], ), )

这篇关于Flutter:仅在传递给文本小部件之前,才可以在字符串中格式化(粗体,斜体等)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆