Flutter:仅在传递给文本小部件之前,才可以在字符串中格式化(粗体,斜体等)吗?
问题内容:
例如 :
String desc = "<bold>Hello<bold> World";
new Text(desc);
问题答案:
您可以为此使用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!'),
], ), )