1
1
import 'dart:collection' ;
2
2
import 'dart:math' ;
3
3
4
+ import 'package:csslib/parser.dart' as cssparser;
5
+ import 'package:csslib/visitor.dart' as css;
6
+ import 'package:flutter/material.dart' ;
4
7
import 'package:flutter_html/flutter_html.dart' ;
8
+ import 'package:flutter_html/src/html_elements.dart' ;
5
9
import 'package:flutter_html/src/layout_element.dart' ;
6
10
import 'package:flutter_html/src/utils.dart' ;
7
11
import 'package:flutter_html/style.dart' ;
8
- import 'package:flutter/material.dart' ;
9
- import 'package:csslib/visitor.dart' as css;
10
12
import 'package:html/dom.dart' as dom;
11
- import 'package:flutter_html/src/html_elements.dart' ;
12
13
import 'package:html/parser.dart' as htmlparser;
13
- import 'package:csslib/parser.dart' as cssparser;
14
14
15
15
typedef OnTap = void Function (String url);
16
16
typedef CustomRender = Widget Function (
@@ -67,7 +67,7 @@ class HtmlParser extends StatelessWidget {
67
67
cleanedTree,
68
68
);
69
69
70
- return RichText (text : parsedTree);
70
+ return StyledText (textSpan : parsedTree, style : cleanedTree.style );
71
71
}
72
72
73
73
/// [parseHTML] converts a string of HTML to a DOM document using the dart `html` library.
@@ -281,14 +281,15 @@ class HtmlParser extends StatelessWidget {
281
281
Padding (
282
282
padding: EdgeInsets .only (
283
283
left: 30 ), //TODO derive this from list padding.
284
- child: RichText (
285
- text : TextSpan (
284
+ child: StyledText (
285
+ textSpan : TextSpan (
286
286
children: tree.children
287
287
? .map ((tree) => parseTree (newContext, tree))
288
288
? .toList () ??
289
289
[],
290
290
style: newContext.style.generateTextStyle (),
291
291
),
292
+ style: newContext.style,
292
293
),
293
294
)
294
295
],
@@ -317,14 +318,15 @@ class HtmlParser extends StatelessWidget {
317
318
},
318
319
),
319
320
},
320
- child: RichText (
321
- text : TextSpan (
321
+ child: StyledText (
322
+ textSpan : TextSpan (
322
323
style: newContext.style.generateTextStyle (),
323
324
children: tree.children
324
325
.map ((tree) => parseTree (newContext, tree))
325
326
.toList () ??
326
327
[],
327
328
),
329
+ style: newContext.style,
328
330
),
329
331
),
330
332
);
@@ -349,14 +351,15 @@ class HtmlParser extends StatelessWidget {
349
351
return WidgetSpan (
350
352
child: Transform .translate (
351
353
offset: Offset (0 , verticalOffset),
352
- child: RichText (
353
- text : TextSpan (
354
+ child: StyledText (
355
+ textSpan : TextSpan (
354
356
style: newContext.style.generateTextStyle (),
355
357
children: tree.children
356
358
.map ((tree) => parseTree (newContext, tree))
357
359
.toList () ??
358
360
[],
359
361
),
362
+ style: newContext.style,
360
363
),
361
364
),
362
365
);
@@ -690,12 +693,36 @@ class ContainerSpan extends StatelessWidget {
690
693
margin: style? .margin,
691
694
alignment: shrinkWrap ? null : style? .alignment,
692
695
child: child ??
693
- RichText (
694
- text : TextSpan (
696
+ StyledText (
697
+ textSpan : TextSpan (
695
698
style: newContext.style.generateTextStyle (),
696
699
children: children,
697
700
),
701
+ style: newContext.style,
698
702
),
699
703
);
700
704
}
701
705
}
706
+
707
+ class StyledText extends StatelessWidget {
708
+ final InlineSpan textSpan;
709
+ final Style style;
710
+
711
+ const StyledText ({
712
+ this .textSpan,
713
+ this .style,
714
+ });
715
+
716
+ @override
717
+ Widget build (BuildContext context) {
718
+ return SizedBox (
719
+ width: style.display == Display .BLOCK || style.display == Display .LIST_ITEM ? double .infinity: null ,
720
+ child: Text .rich (
721
+ textSpan,
722
+ style: style.generateTextStyle (),
723
+ textAlign: style.textAlign,
724
+ textDirection: style.direction,
725
+ ),
726
+ );
727
+ }
728
+ }
0 commit comments