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

如何在 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);
                    }
                  }
                },
              ),
            ),
          )

https://stackoverflow.com/questions/53815485/

相关文章:

websocket - 如何在 Flutter 上使用 SignalR?

flutter - 导航器使用 pushNamed 传递参数

android - Flutter - 如何使列屏幕可滚动

flutter - 如何在 flutter 中检索当前的类名?

dart - 如何自定义日期选择器

android - 可以在 Android Studio 中使用 Flutter 开发 IOS 吗?

dart - 与容器装饰一起使用时,墨水瓶不显示波纹

flutter - 相机和图像选择器插件有什么区别?

database - Flutter中的Sqlite,数据库 Assets 如何工作

flutter - 子类化扩展 StatelessWidget 或 StatefulWidget 类