@@ -84,9 +84,11 @@ class BlockText extends StatelessWidget {
84
84
final EdgeInsets padding;
85
85
final EdgeInsets margin;
86
86
final Decoration decoration;
87
+ final bool shrinkToFit;
87
88
88
89
BlockText ({
89
90
@required this .child,
91
+ @required this .shrinkToFit,
90
92
this .padding,
91
93
this .margin,
92
94
this .decoration,
@@ -95,7 +97,7 @@ class BlockText extends StatelessWidget {
95
97
@override
96
98
Widget build (BuildContext context) {
97
99
return Container (
98
- width: double .infinity,
100
+ width: shrinkToFit ? null : double .infinity,
99
101
padding: this .padding,
100
102
margin: this .margin,
101
103
decoration: this .decoration,
@@ -147,7 +149,7 @@ class ParseContext {
147
149
148
150
class HtmlRichTextParser extends StatelessWidget {
149
151
HtmlRichTextParser ({
150
- @required this .width ,
152
+ this .shrinkToFit ,
151
153
this .onLinkTap,
152
154
this .renderNewlines = false ,
153
155
this .html,
@@ -167,7 +169,7 @@ class HtmlRichTextParser extends StatelessWidget {
167
169
168
170
final double indentSize = 10.0 ;
169
171
170
- final double width ;
172
+ final bool shrinkToFit ;
171
173
final onLinkTap;
172
174
final bool renderNewlines;
173
175
final String html;
@@ -417,6 +419,7 @@ class HtmlRichTextParser extends StatelessWidget {
417
419
));
418
420
}
419
421
BlockText blockText = BlockText (
422
+ shrinkToFit: shrinkToFit,
420
423
margin: EdgeInsets .only (
421
424
top: 8.0 ,
422
425
bottom: 8.0 ,
@@ -430,8 +433,10 @@ class HtmlRichTextParser extends StatelessWidget {
430
433
);
431
434
parseContext.rootWidgetList.add (blockText);
432
435
} else {
433
- parseContext.rootWidgetList
434
- .add (BlockText (child: RichText (text: span)));
436
+ parseContext.rootWidgetList.add (BlockText (
437
+ child: RichText (text: span),
438
+ shrinkToFit: shrinkToFit,
439
+ ));
435
440
}
436
441
437
442
// this allows future items to be added as children of this item
@@ -591,6 +596,7 @@ class HtmlRichTextParser extends StatelessWidget {
591
596
} else {
592
597
// start a new block element for this link and its text
593
598
BlockText blockElement = BlockText (
599
+ shrinkToFit: shrinkToFit,
594
600
margin: EdgeInsets .only (
595
601
left: parseContext.indentLevel * indentSize, top: 10.0 ),
596
602
child: RichText (text: span),
@@ -813,6 +819,7 @@ class HtmlRichTextParser extends StatelessWidget {
813
819
}
814
820
if (node.attributes['alt' ] != null ) {
815
821
parseContext.rootWidgetList.add (BlockText (
822
+ shrinkToFit: shrinkToFit,
816
823
margin:
817
824
EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
818
825
padding: EdgeInsets .all (0.0 ),
@@ -836,6 +843,7 @@ class HtmlRichTextParser extends StatelessWidget {
836
843
leadingChar = parseContext.listCount.toString () + '.' ;
837
844
}
838
845
BlockText blockText = BlockText (
846
+ shrinkToFit: shrinkToFit,
839
847
margin: EdgeInsets .only (
840
848
left: parseContext.indentLevel * indentSize, top: 3.0 ),
841
849
child: RichText (
@@ -907,6 +915,7 @@ class HtmlRichTextParser extends StatelessWidget {
907
915
));
908
916
}
909
917
BlockText blockText = BlockText (
918
+ shrinkToFit: shrinkToFit,
910
919
margin: node.localName != 'body'
911
920
? _customEdgeInsets ??
912
921
EdgeInsets .only (
0 commit comments