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
@@ -131,11 +135,20 @@ For a full example, see [here](https://github.com/Sub6Resources/flutter_html/tre
131
135
132
136
Below, you will find brief descriptions of the parameters the`Html` widget accepts and some code snippets to help you use this package.
133
137
138
+
## Constructors:
139
+
140
+
The package currently has two different constructors - `Html()` and `Html.fromDom()`.
141
+
142
+
The `Html()` constructor is for those who would like to directly pass HTML from the source to the package to be rendered.
143
+
144
+
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.
145
+
134
146
### Parameters:
135
147
136
148
| Parameters | Description |
137
149
|--------------|-----------------|
138
-
|`data`| The HTML data passed to the `Html` widget. This is required and cannot be null. |
150
+
|`data`| The HTML data passed to the `Html` widget. This is required and cannot be null when using `Html()`. |
151
+
|`document`| The DOM document passed to the `Html` widget. This is required and cannot be null when using `Html.fromDom()`. |
139
152
|`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. |
140
153
|`customRender`| A powerful API that allows you to customize everything when rendering a specific HTML tag. |
141
154
|`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. |
@@ -148,7 +161,7 @@ Below, you will find brief descriptions of the parameters the`Html` widget accep
148
161
149
162
### Data:
150
163
151
-
The HTML data passed to the `Html` widget as a `String`. This is required and cannot be null.
164
+
The HTML data passed to the `Html` widget as a `String`. This is required and cannot be null when using `Html`.
152
165
Any HTML tags in the `String` that are not supported by the package will not be rendered.
153
166
154
167
#### Example Usage - Data:
@@ -169,6 +182,36 @@ Widget html = Html(
169
182
);
170
183
```
171
184
185
+
### Document:
186
+
187
+
The DOM document passed to the `Html` widget as a `Document`. This is required and cannot be null when using `Html.fromDom()`.
188
+
Any HTML tags in the document that are not supported by the package will not be rendered.
189
+
Using the `Html.fromDom()` constructor can be useful when you would like to sanitize the HTML string yourself before passing it to the package.
190
+
191
+
#### Example Usage - Document:
192
+
193
+
```dart
194
+
import 'package:html/parser.dart' as htmlparser;
195
+
import 'package:html/dom.dart' as dom;
196
+
...
197
+
String htmlData = """<div>
198
+
<h1>Demo Page</h1>
199
+
<p>This is a fantastic product that you should buy!</p>
0 commit comments