string - 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 的小部件喜欢 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!'), 
], ), )

https://stackoverflow.com/questions/51093559/

相关文章:

text - 如何消除 flutter 上文本上方和下方的间隙

animation - 如何为 Sprite 设置动画以移动到 flutter 的任意点?

firebase - 如何使用 flutter 删除 Firebase 存储文件?

dart - 根据条件添加小部件

dart - 带有命名路线的 flutter 持久导航栏?

flutter - 附加到多个 ScrollView 的 ScrollController

android - 如何使用 Flutter 构建能够拖动到全屏的底部表单小部件?

dart - 如何在 flutter 图像选择器中将图像添加到 Firestore

flutter - 如何使用flutter firebase_ml_vision插件实时读取字符或条

firebase - Flutter Firebase BLoC 模式