You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-2Lines changed: 45 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,13 @@ A Flutter widget for rendering HTML and CSS as Flutter widgets.
33
33
34
34
-[API Reference](#api-reference)
35
35
36
+
-[Constructors](#constructors)
37
+
36
38
-[Parameters Table](#parameters)
37
39
38
40
-[Data](#data)
41
+
42
+
-[Document](#document)
39
43
40
44
-[onLinkTap](#onlinktap)
41
45
@@ -137,11 +141,20 @@ For a full example, see [here](https://github.com/Sub6Resources/flutter_html/tre
137
141
138
142
Below, you will find brief descriptions of the parameters the`Html` widget accepts and some code snippets to help you use this package.
139
143
144
+
## Constructors:
145
+
146
+
The package currently has two different constructors - `Html()` and `Html.fromDom()`.
147
+
148
+
The `Html()` constructor is for those who would like to directly pass HTML from the source to the package to be rendered.
149
+
150
+
If you would like to modify or sanitize the HTML before rendering it, then `Html.fromDom()` is for you - you can convert the HTML string to a `Document` and use its methods to modify the HTML as you wish. Then, you can directly pass the modified `Document` to the package. This eliminates the need to parse the modified `Document` back to a string, pass to `Html()`, and convert back to a `Document`, thus cutting down on load times.
151
+
140
152
### Parameters:
141
153
142
154
| Parameters | Description |
143
155
|--------------|-----------------|
144
-
|`data`| The HTML data passed to the `Html` widget. This is required and cannot be null. |
156
+
|`data`| The HTML data passed to the `Html` widget. This is required and cannot be null when using `Html()`. |
157
+
|`document`| The DOM document passed to the `Html` widget. This is required and cannot be null when using `Html.fromDom()`. |
145
158
|`onLinkTap`| A function that defines what the widget should do when a link is tapped. The function exposes the `src` of the link as a `String` to use in your implementation. |
146
159
|`customRender`| A powerful API that allows you to customize everything when rendering a specific HTML tag. |
147
160
|`onImageError`| A function that defines what the widget should do when an image fails to load. The function exposes the exception `Object` and `StackTrace` to use in your implementation. |
@@ -155,7 +168,7 @@ Below, you will find brief descriptions of the parameters the`Html` widget accep
155
168
156
169
### Data:
157
170
158
-
The HTML data passed to the `Html` widget as a `String`. This is required and cannot be null.
171
+
The HTML data passed to the `Html` widget as a `String`. This is required and cannot be null when using `Html`.
159
172
Any HTML tags in the `String` that are not supported by the package will not be rendered.
160
173
161
174
#### Example Usage - Data:
@@ -176,6 +189,36 @@ Widget html = Html(
176
189
);
177
190
```
178
191
192
+
### Document:
193
+
194
+
The DOM document passed to the `Html` widget as a `Document`. This is required and cannot be null when using `Html.fromDom()`.
195
+
Any HTML tags in the document that are not supported by the package will not be rendered.
196
+
Using the `Html.fromDom()` constructor can be useful when you would like to sanitize the HTML string yourself before passing it to the package.
197
+
198
+
#### Example Usage - Document:
199
+
200
+
```dart
201
+
import 'package:html/parser.dart' as htmlparser;
202
+
import 'package:html/dom.dart' as dom;
203
+
...
204
+
String htmlData = """<div>
205
+
<h1>Demo Page</h1>
206
+
<p>This is a fantastic product that you should buy!</p>
0 commit comments