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"); }
This is my 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>.”
i user flutter_html_view: "^0.5.10" this plugin
To display valid HTML you can set the src field to the following: _src = "data:text/html;charset=utf-8," + Uri. encodeComponent("HTML_CONTENT_HERE"); For the package you can also pass markdown to the src and it will convert it for you.
With this object you can obtain specific Element s of the DOM with methods like getElementById , getElementsByClassName , and getElementsByTagName . From there you can obtain the innerHtml of each Element that is returned and put together the output string you desire.
Strip HTML tags without Package String parsedstring2 = html. replaceAll(exp, ' '); print(parsedstring2); //output with space: Hello This is fluttercampus.com ,Bye! Here, we remove all HTML tags using Regex expression. You can also use RegExp(r'<[^>]*>|&[^;]+;') to strip HTML tags.
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
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); } } }, ), ), )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With