@@ -60,15 +60,15 @@ class Html extends StatefulWidget {
6060 this .onImageTap,
6161 this .tagsList = const [],
6262 this .style = const {},
63- }) : document = null ,
63+ }) : documentElement = null ,
6464 assert (data != null ),
6565 _anchorKey = anchorKey ?? GlobalKey (),
6666 super (key: key);
6767
6868 Html .fromDom ({
6969 Key ? key,
7070 GlobalKey ? anchorKey,
71- @required this . document,
71+ @required dom. Document ? document,
7272 this .onLinkTap,
7373 this .onAnchorTap,
7474 this .customRenders = const {},
@@ -80,6 +80,25 @@ class Html extends StatefulWidget {
8080 this .style = const {},
8181 }) : data = null ,
8282 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 ),
83102 _anchorKey = anchorKey ?? GlobalKey (),
84103 super (key: key);
85104
@@ -89,8 +108,8 @@ class Html extends StatefulWidget {
89108 /// The HTML data passed to the widget as a String
90109 final String ? data;
91110
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 ;
94113
95114 /// A function that defines what to do when a link is tapped
96115 final OnTap ? onLinkTap;
@@ -135,13 +154,13 @@ class Html extends StatefulWidget {
135154}
136155
137156class _HtmlState extends State <Html > {
138- late final dom.Document doc ;
157+ late final dom.Element documentElement ;
139158
140159 @override
141160 void initState () {
142161 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 ! ;
145164 }
146165
147166 @override
@@ -150,7 +169,7 @@ class _HtmlState extends State<Html> {
150169 width: widget.shrinkWrap ? null : MediaQuery .of (context).size.width,
151170 child: HtmlParser (
152171 key: widget._anchorKey,
153- htmlData: doc ,
172+ htmlData: documentElement ,
154173 onLinkTap: widget.onLinkTap,
155174 onAnchorTap: widget.onAnchorTap,
156175 onImageTap: widget.onImageTap,
@@ -174,7 +193,7 @@ class SelectableHtml extends StatefulWidget {
174193 ///
175194 /// **Attributes**
176195 /// **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).
178197 ///
179198 /// **onLinkTap** This function is called whenever a link (`<a href>` )
180199 /// is tapped.
@@ -213,15 +232,15 @@ class SelectableHtml extends StatefulWidget {
213232 this .tagsList = const [],
214233 this .selectionControls,
215234 this .scrollPhysics,
216- }) : document = null ,
235+ }) : documentElement = null ,
217236 assert (data != null ),
218237 _anchorKey = anchorKey ?? GlobalKey (),
219238 super (key: key);
220239
221240 SelectableHtml .fromDom ({
222241 Key ? key,
223242 GlobalKey ? anchorKey,
224- required this . document,
243+ @ required dom. Document ? document,
225244 this .onLinkTap,
226245 this .onAnchorTap,
227246 this .onCssParseError,
@@ -233,6 +252,25 @@ class SelectableHtml extends StatefulWidget {
233252 this .scrollPhysics,
234253 }) : data = null ,
235254 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 ),
236274 _anchorKey = anchorKey ?? GlobalKey (),
237275 super (key: key);
238276
@@ -242,8 +280,8 @@ class SelectableHtml extends StatefulWidget {
242280 /// The HTML data passed to the widget as a String
243281 final String ? data;
244282
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 ;
247285
248286 /// A function that defines what to do when a link is tapped
249287 final OnTap ? onLinkTap;
@@ -283,13 +321,12 @@ class SelectableHtml extends StatefulWidget {
283321}
284322
285323class _SelectableHtmlState extends State <SelectableHtml > {
286- late final dom.Document doc ;
324+ late final dom.Element documentElement ;
287325
288326 @override
289327 void initState () {
290328 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! ;
293330 }
294331
295332 @override
@@ -298,7 +335,7 @@ class _SelectableHtmlState extends State<SelectableHtml> {
298335 width: widget.shrinkWrap ? null : MediaQuery .of (context).size.width,
299336 child: HtmlParser (
300337 key: widget._anchorKey,
301- htmlData: doc ,
338+ htmlData: documentElement ,
302339 onLinkTap: widget.onLinkTap,
303340 onAnchorTap: widget.onAnchorTap,
304341 onImageTap: null ,
0 commit comments