gpt4 book ai didi

android - 如何在文本小部件 flutter 中显示 html 字符串

转载 作者:IT老高 更新时间:2023-10-28 12:36:47 24 4
gpt4 key购买 nike

如何在 Flutter 中显示 html 标签字符串,我尝试了一个插件,但它不起作用。

new HtmlView(
data: html,
baseURL: "", // optional, type String
onLaunchFail: (url) { // optional, type Function
print("launch $url failed");
}

这是我的html

“Follow<a class='sup'><sup>pl</sup></a> what was sent down to you from your Lord, and do not follow other guardians apart from Him. Little do <span class='h'>you remind yourselves</span><a class='f'><sup f=2437>1</sup></a>.”   

我的用户flutter_html_view:“^0.5.10”这个插件

最佳答案

这个插件没有任何问题,我只是用你的 HTML 创建了一个示例,它工作正常。尝试用下面的代码段替换,看看是否有效。

dependencies:
flutter_html: ^0.8.2

以及用于渲染 html 的导入和代码

import 'package:flutter_html/flutter_html.dart';
import 'package:html/dom.dart' as dom;


body: new Center(
child: SingleChildScrollView(
child: Html(
data: """
<div>Follow<a class='sup'><sup>pl</sup></a>
Below hr
<b>Bold</b>
<h1>what was sent down to you from your Lord</h1>,
and do not follow other guardians apart from Him. Little do
<span class='h'>you remind yourselves</span><a class='f'><sup f=2437>1</sup></a></div>
""",
padding: EdgeInsets.all(8.0),
onLinkTap: (url) {
print("Opening $url...");
},
customRender: (node, children) {
if (node is dom.Element) {
switch (node.localName) {
case "custom_tag": // using this, you can handle custom tags in your HTML
return Column(children: children);
}
}
},
),
),
)

关于android - 如何在文本小部件 flutter 中显示 html 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53815485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com