Flutter Widget from HTML
此软件包通过使用cached_network_image或url_launcher等外部依赖项,扩展了flutter_widget_from_html_core软件包,提供了额外功能。它应该足以作为快速入门,但如果您不喜欢依赖项,也可以直接使用核心包。
用法
要使用此插件,请将flutter_widget_from_html添加为pubspec.yaml文件中的依赖项。
有关灵感,请参阅示例应用程序。
示例
注意:HtmlWidget.config是可选的,有关所有可用配置键及其默认值,请参阅dartdoc。
class HelloWorldScreen extends StatelessWidget {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text('HelloWorldScreen'),
),
body: ListView(
children: <Widget>[
HtmlWidget("""<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<p>A paragraph with <strong>strong</strong> <em>emphasized</em> text.</p>
<p>And of course, cat image: <img src="https://media.giphy.com/media/6VoDJzfRjJNbG/giphy-downsized.gif" /></p>
<div style="text-align: center">Source: <a href="https://gph.is/QFgPA0">https://gph.is/QFgPA0</a></div>
"""),
],
));
}

特点
此软件包拥有flutter_widget_from_html_core的所有功能以及一些不错的附加功能
- 使用主题强调色渲染 A 标签,通过
url_launcher启动URL - 使用
CachedNetworkImage和内边距(Config.imagePadding)渲染 IMG 标签 - 使用标记和内边距(
Config.listBullet,Config.listPaddingLeft)渲染列表(OL/UL) - 使用内边距(
Config.textPadding)渲染文本 - 支持相对URL(A href, IMG src)