How to display html text in flutter?
Asked Answered
N

3

7

I have to display html text as like android provides Html.fromHtml to display htmltextview does flutter provides anythings to display html text?

Narcotism answered 12/2, 2019 at 7:19 Comment(0)
W
7

There are packages that do this

Wreckage answered 12/2, 2019 at 7:20 Comment(2)
flutter_html is not working in all tags include that which they provides. – Narcotism
As I said a "subset". Translating from HTML to Flutter widgets isn't trivial. – Benitobenjamen
E
3

Add the following to your pubspec.yaml file:

dependencies:
  flutter_html:

Currently Supported HTML Tags:

a, abbr, acronym, address, article, aside, b, bdi, bdo, big, blockquote, body, br, caption, cite, code, data, dd, del, dfn, div, dl, dt, em, figcaption, figure, footer, h1, h2, h3, h4, h5, h6, header, hr, i, img, ins, kbd, li, main, mark, nav, noscript, ol, p, pre, q, rp, rt, ruby, s, samp, section, small, span, strike, strong, sub, sup, table, tbody, td, template, tfoot, th, thead, time, tr, tt, u, ul, var

Example Usage:

Column(
   mainAxisAlignment: MainAxisAlignment.start,
   crossAxisAlignment: CrossAxisAlignment.start,
   children: [
      new Html(
         data: "<b>Hai</b>,
          defaultTextStyle: TextStyle(fontSize: 15),
       ),
     ],
)
Exploiter answered 28/9, 2020 at 11:5 Comment(1)
This is great if you want to hard code your html into your app, but if you're pulling from firestore and you need different styling for different documents (or if you want to make your text selectable), this plugin does not work. – Grebe
D
1
  1. That converts HTML code into well-structured Flutter widgets.

flutter pub add flutter_widget_from_html_core

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):πŸ”Ό

  1. Refer this link πŸ”½

flutter_widget_from_html_core

FeaturesπŸ”½

read this

  1. Example

package example

  1. normally integrate

import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';

Scaffold(
        appBar: AppBar(
          title: Text('Appbar'),
        ),
        body: Center(
          child: HtmlWidget('Hello World!'),
        ),
      );
Deontology answered 12/2 at 11:59 Comment(1)
Please read How to Answer and edit your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Barbellate

© 2022 - 2024 β€” McMap. All rights reserved.