小编典典

Flutter:仅在传递给文本小部件之前,才可以在字符串中格式化(粗体,斜体等)吗?

flutter

例如 :

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

阅读 372

收藏
2020-08-13

共1个答案

小编典典

您可以为此使用flutter_html_view包。

String html = '<bold>Hello<bold> World';

new HtmlTextView(data: html);

如果您只想使用不同的样式,则可以使用像这样RichText小部件。TextSpans

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!'), 
], ), )
2020-08-13