如何在文本小部件颤动中显示html字符串 [英] How to show html string in text widget flutter

查看:109
本文介绍了如何在文本小部件颤动中显示html字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在颤动中显示html标签字符串,我尝试了一个插件,但无法正常工作.

How to show html tag string in flutter, i have tried a plugin and its not working.

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"此插件

i user flutter_html_view: "^0.5.10" this plugin

推荐答案

此插件没有任何问题,我刚刚使用您的HTML创建了一个示例,并且工作正常.尝试用以下代码段替换,看看是否可行.

This plugin doesn`t have any issue, I just created a sample with your HTML and it works fine. Try to replace with below snippet and see if that works.

dependencies:
  flutter_html: ^0.8.2

并导入和编码以呈现html

and imports and code to render 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);
                    }
                  }
                },
              ),
            ),
          )

这篇关于如何在文本小部件颤动中显示html字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆