@@ -117,22 +117,20 @@ class ParseContext {
117
117
}
118
118
}
119
119
120
- class HtmlRichTextParser {
120
+ class HtmlRichTextParser extends StatelessWidget {
121
121
HtmlRichTextParser ({
122
122
@required this .width,
123
123
this .onLinkTap,
124
124
this .renderNewlines = false ,
125
- this .customRender,
126
- this .context,
125
+ this .html,
127
126
});
128
127
129
128
final double indentSize = 10.0 ;
130
129
131
130
final double width;
132
131
final onLinkTap;
133
132
final bool renderNewlines;
134
- final CustomRender customRender;
135
- final BuildContext context;
133
+ final String html;
136
134
137
135
// style elements set a default style
138
136
// for all child nodes
@@ -210,7 +208,10 @@ class HtmlRichTextParser {
210
208
}
211
209
212
210
// Parses an html string and returns a list of RichText widgets that represent the body of your html document.
213
- List <Widget > parse (String data) {
211
+
212
+ @override
213
+ Widget build (BuildContext context) {
214
+ String data = html;
214
215
215
216
if (renderNewlines) {
216
217
data = data.replaceAll ("\n " , "<br />" );
@@ -229,7 +230,7 @@ class HtmlRichTextParser {
229
230
// _parseNode(body, parseContext);
230
231
231
232
// eliminate empty widgets
232
- List <Widget > retval = [];
233
+ List <Widget > children = [];
233
234
widgetList.forEach ((dynamic w){
234
235
if (w is BlockText ) {
235
236
if (w.child.text == null ) return ;
@@ -239,9 +240,12 @@ class HtmlRichTextParser {
239
240
} else if (w is LinkTextSpan ) {
240
241
if (w.text.isEmpty && w.children.isEmpty) return ;
241
242
}
242
- retval .add (w);
243
+ children .add (w);
243
244
});
244
- return retval;
245
+
246
+ return Column (
247
+ children: children,
248
+ );
245
249
}
246
250
247
251
// THE WORKHORSE FUNCTION!!
@@ -492,8 +496,10 @@ class HtmlRichTextParser {
492
496
case "li" :
493
497
String leadingChar = parseContext.listChar;
494
498
if (parseContext.blockType == 'ol' ) {
495
- nextContext.listCount += 1 ;
496
- leadingChar = nextContext.listCount.toString () + '.' ;
499
+ // nextContext will handle nodes under this 'li'
500
+ // but we want to increment the count at this level
501
+ parseContext.listCount += 1 ;
502
+ leadingChar = parseContext.listCount.toString () + '.' ;
497
503
}
498
504
BlockText blockText = BlockText (
499
505
margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 3.0 ),
@@ -651,18 +657,20 @@ class HtmlRichTextParser {
651
657
652
658
653
659
654
- class HtmlOldParser {
660
+ class HtmlOldParser extends StatelessWidget {
655
661
HtmlOldParser ({
656
662
@required this .width,
657
663
this .onLinkTap,
658
664
this .renderNewlines = false ,
659
665
this .customRender,
666
+ this .html,
660
667
});
661
668
662
669
final double width;
663
670
final OnLinkTap onLinkTap;
664
671
final bool renderNewlines;
665
672
final CustomRender customRender;
673
+ final String html;
666
674
667
675
static const _supportedElements = [
668
676
"a" ,
@@ -739,6 +747,14 @@ class HtmlOldParser {
739
747
"var" ,
740
748
];
741
749
750
+ @override
751
+ Widget build (BuildContext context) {
752
+ return Wrap (
753
+ alignment: WrapAlignment .start,
754
+ children: parse (html),
755
+ );
756
+ }
757
+
742
758
///Parses an html string and returns a list of widgets that represent the body of your html document.
743
759
List <Widget > parse (String data) {
744
760
List <Widget > widgetList = new List <Widget >();
0 commit comments