@@ -60,15 +60,15 @@ class Html extends StatefulWidget {
60
60
this .onImageTap,
61
61
this .tagsList = const [],
62
62
this .style = const {},
63
- }) : document = null ,
63
+ }) : documentElement = null ,
64
64
assert (data != null ),
65
65
_anchorKey = anchorKey ?? GlobalKey (),
66
66
super (key: key);
67
67
68
68
Html .fromDom ({
69
69
Key ? key,
70
70
GlobalKey ? anchorKey,
71
- @required this . document,
71
+ @required dom. Document ? document,
72
72
this .onLinkTap,
73
73
this .onAnchorTap,
74
74
this .customRenders = const {},
@@ -80,6 +80,25 @@ class Html extends StatefulWidget {
80
80
this .style = const {},
81
81
}) : data = null ,
82
82
assert (document != null ),
83
+ this .documentElement = document! .documentElement,
84
+ _anchorKey = anchorKey ?? GlobalKey (),
85
+ super (key: key);
86
+
87
+ Html .fromElement ({
88
+ Key ? key,
89
+ GlobalKey ? anchorKey,
90
+ @required this .documentElement,
91
+ this .onLinkTap,
92
+ this .onAnchorTap,
93
+ this .customRenders = const {},
94
+ this .onCssParseError,
95
+ this .onImageError,
96
+ this .shrinkWrap = false ,
97
+ this .onImageTap,
98
+ this .tagsList = const [],
99
+ this .style = const {},
100
+ }) : data = null ,
101
+ assert (documentElement != null ),
83
102
_anchorKey = anchorKey ?? GlobalKey (),
84
103
super (key: key);
85
104
@@ -89,8 +108,8 @@ class Html extends StatefulWidget {
89
108
/// The HTML data passed to the widget as a String
90
109
final String ? data;
91
110
92
- /// The HTML data passed to the widget as a pre-processed [dom.Document ]
93
- final dom.Document ? document ;
111
+ /// The HTML data passed to the widget as a pre-processed [dom.Element ]
112
+ final dom.Element ? documentElement ;
94
113
95
114
/// A function that defines what to do when a link is tapped
96
115
final OnTap ? onLinkTap;
@@ -135,13 +154,13 @@ class Html extends StatefulWidget {
135
154
}
136
155
137
156
class _HtmlState extends State <Html > {
138
- late final dom.Document doc ;
157
+ late final dom.Element documentElement ;
139
158
140
159
@override
141
160
void initState () {
142
161
super .initState ();
143
- doc =
144
- widget.data != null ? HtmlParser .parseHTML (widget.data! ) : widget.document ! ;
162
+ documentElement =
163
+ widget.data != null ? HtmlParser .parseHTML (widget.data! ) : widget.documentElement ! ;
145
164
}
146
165
147
166
@override
@@ -150,7 +169,7 @@ class _HtmlState extends State<Html> {
150
169
width: widget.shrinkWrap ? null : MediaQuery .of (context).size.width,
151
170
child: HtmlParser (
152
171
key: widget._anchorKey,
153
- htmlData: doc ,
172
+ htmlData: documentElement ,
154
173
onLinkTap: widget.onLinkTap,
155
174
onAnchorTap: widget.onAnchorTap,
156
175
onImageTap: widget.onImageTap,
@@ -174,7 +193,7 @@ class SelectableHtml extends StatefulWidget {
174
193
///
175
194
/// **Attributes**
176
195
/// **data** *required* takes in a String of HTML data (required only for `Html` constructor).
177
- /// **document ** *required* takes in a Document of HTML data (required only for `Html.fromDom` constructor).
196
+ /// **documentElement ** *required* takes in a Element of HTML data (required only for `Html.fromDom` and `Html.fromElement ` constructor).
178
197
///
179
198
/// **onLinkTap** This function is called whenever a link (`<a href>` )
180
199
/// is tapped.
@@ -213,15 +232,15 @@ class SelectableHtml extends StatefulWidget {
213
232
this .tagsList = const [],
214
233
this .selectionControls,
215
234
this .scrollPhysics,
216
- }) : document = null ,
235
+ }) : documentElement = null ,
217
236
assert (data != null ),
218
237
_anchorKey = anchorKey ?? GlobalKey (),
219
238
super (key: key);
220
239
221
240
SelectableHtml .fromDom ({
222
241
Key ? key,
223
242
GlobalKey ? anchorKey,
224
- required this . document,
243
+ @ required dom. Document ? document,
225
244
this .onLinkTap,
226
245
this .onAnchorTap,
227
246
this .onCssParseError,
@@ -233,6 +252,25 @@ class SelectableHtml extends StatefulWidget {
233
252
this .scrollPhysics,
234
253
}) : data = null ,
235
254
assert (document != null ),
255
+ this .documentElement = document! .documentElement,
256
+ _anchorKey = anchorKey ?? GlobalKey (),
257
+ super (key: key);
258
+
259
+ SelectableHtml .fromElement ({
260
+ Key ? key,
261
+ GlobalKey ? anchorKey,
262
+ @required this .documentElement,
263
+ this .onLinkTap,
264
+ this .onAnchorTap,
265
+ this .onCssParseError,
266
+ this .shrinkWrap = false ,
267
+ this .style = const {},
268
+ this .customRenders = const {},
269
+ this .tagsList = const [],
270
+ this .selectionControls,
271
+ this .scrollPhysics,
272
+ }) : data = null ,
273
+ assert (documentElement != null ),
236
274
_anchorKey = anchorKey ?? GlobalKey (),
237
275
super (key: key);
238
276
@@ -242,8 +280,8 @@ class SelectableHtml extends StatefulWidget {
242
280
/// The HTML data passed to the widget as a String
243
281
final String ? data;
244
282
245
- /// The HTML data passed to the widget as a pre-processed [dom.Document ]
246
- final dom.Document ? document ;
283
+ /// The HTML data passed to the widget as a pre-processed [dom.Element ]
284
+ final dom.Element ? documentElement ;
247
285
248
286
/// A function that defines what to do when a link is tapped
249
287
final OnTap ? onLinkTap;
@@ -283,13 +321,12 @@ class SelectableHtml extends StatefulWidget {
283
321
}
284
322
285
323
class _SelectableHtmlState extends State <SelectableHtml > {
286
- late final dom.Document doc ;
324
+ late final dom.Element documentElement ;
287
325
288
326
@override
289
327
void initState () {
290
328
super .initState ();
291
- doc =
292
- widget.data != null ? HtmlParser .parseHTML (widget.data! ) : widget.document! ;
329
+ documentElement = widget.data != null ? HtmlParser .parseHTML (widget.data! ) : widget.documentElement! ;
293
330
}
294
331
295
332
@override
@@ -298,7 +335,7 @@ class _SelectableHtmlState extends State<SelectableHtml> {
298
335
width: widget.shrinkWrap ? null : MediaQuery .of (context).size.width,
299
336
child: HtmlParser (
300
337
key: widget._anchorKey,
301
- htmlData: doc ,
338
+ htmlData: documentElement ,
302
339
onLinkTap: widget.onLinkTap,
303
340
onAnchorTap: widget.onAnchorTap,
304
341
onImageTap: null ,
0 commit comments