Skip to content

Commit 3a6170b

Browse files
committed
Move parsing of html string to Html() constructor
1 parent 4f1306f commit 3a6170b

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

lib/flutter_html.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ class Html extends StatelessWidget {
9292
@override
9393
Widget build(BuildContext context) {
9494
final double width = shrinkWrap ? null : MediaQuery.of(context).size.width;
95-
95+
final dom.Document doc = data != null ? HtmlParser.parseHTML(data) : document;
9696
return Container(
9797
width: width,
9898
child: HtmlParser(
99-
htmlData: data,
100-
userDocument: document,
99+
htmlData: doc,
101100
onLinkTap: onLinkTap,
102101
onImageTap: onImageTap,
103102
onImageError: onImageError,

lib/html_parser.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ typedef CustomRender = dynamic Function(
2525
);
2626

2727
class HtmlParser extends StatelessWidget {
28-
final String htmlData;
29-
final dom.Document userDocument;
28+
final dom.Document htmlData;
3029
final OnTap onLinkTap;
3130
final OnTap onImageTap;
3231
final ImageErrorListener onImageError;
@@ -40,7 +39,6 @@ class HtmlParser extends StatelessWidget {
4039

4140
HtmlParser({
4241
@required this.htmlData,
43-
@required this.userDocument,
4442
this.onLinkTap,
4543
this.onImageTap,
4644
this.onImageError,
@@ -54,11 +52,8 @@ class HtmlParser extends StatelessWidget {
5452

5553
@override
5654
Widget build(BuildContext context) {
57-
dom.Document document;
58-
if (userDocument == null) document = parseHTML(htmlData);
59-
if (htmlData == null) document = userDocument;
6055
StyledElement lexedTree = lexDomTree(
61-
document,
56+
htmlData,
6257
customRender?.keys?.toList() ?? [],
6358
blacklistedElements,
6459
navigationDelegateForIframe,

0 commit comments

Comments
 (0)