@@ -84,9 +84,11 @@ class BlockText extends StatelessWidget {
8484 final EdgeInsets padding;
8585 final EdgeInsets margin;
8686 final Decoration decoration;
87+ final bool shrinkToFit;
8788
8889 BlockText ({
8990 @required this .child,
91+ @required this .shrinkToFit,
9092 this .padding,
9193 this .margin,
9294 this .decoration,
@@ -95,7 +97,7 @@ class BlockText extends StatelessWidget {
9597 @override
9698 Widget build (BuildContext context) {
9799 return Container (
98- width: double .infinity,
100+ width: shrinkToFit ? null : double .infinity,
99101 padding: this .padding,
100102 margin: this .margin,
101103 decoration: this .decoration,
@@ -147,7 +149,7 @@ class ParseContext {
147149
148150class HtmlRichTextParser extends StatelessWidget {
149151 HtmlRichTextParser ({
150- @required this .width ,
152+ this .shrinkToFit ,
151153 this .onLinkTap,
152154 this .renderNewlines = false ,
153155 this .html,
@@ -167,7 +169,7 @@ class HtmlRichTextParser extends StatelessWidget {
167169
168170 final double indentSize = 10.0 ;
169171
170- final double width ;
172+ final bool shrinkToFit ;
171173 final onLinkTap;
172174 final bool renderNewlines;
173175 final String html;
@@ -417,6 +419,7 @@ class HtmlRichTextParser extends StatelessWidget {
417419 ));
418420 }
419421 BlockText blockText = BlockText (
422+ shrinkToFit: shrinkToFit,
420423 margin: EdgeInsets .only (
421424 top: 8.0 ,
422425 bottom: 8.0 ,
@@ -430,8 +433,10 @@ class HtmlRichTextParser extends StatelessWidget {
430433 );
431434 parseContext.rootWidgetList.add (blockText);
432435 } 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+ ));
435440 }
436441
437442 // this allows future items to be added as children of this item
@@ -591,6 +596,7 @@ class HtmlRichTextParser extends StatelessWidget {
591596 } else {
592597 // start a new block element for this link and its text
593598 BlockText blockElement = BlockText (
599+ shrinkToFit: shrinkToFit,
594600 margin: EdgeInsets .only (
595601 left: parseContext.indentLevel * indentSize, top: 10.0 ),
596602 child: RichText (text: span),
@@ -813,6 +819,7 @@ class HtmlRichTextParser extends StatelessWidget {
813819 }
814820 if (node.attributes['alt' ] != null ) {
815821 parseContext.rootWidgetList.add (BlockText (
822+ shrinkToFit: shrinkToFit,
816823 margin:
817824 EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
818825 padding: EdgeInsets .all (0.0 ),
@@ -836,6 +843,7 @@ class HtmlRichTextParser extends StatelessWidget {
836843 leadingChar = parseContext.listCount.toString () + '.' ;
837844 }
838845 BlockText blockText = BlockText (
846+ shrinkToFit: shrinkToFit,
839847 margin: EdgeInsets .only (
840848 left: parseContext.indentLevel * indentSize, top: 3.0 ),
841849 child: RichText (
@@ -907,6 +915,7 @@ class HtmlRichTextParser extends StatelessWidget {
907915 ));
908916 }
909917 BlockText blockText = BlockText (
918+ shrinkToFit: shrinkToFit,
910919 margin: node.localName != 'body'
911920 ? _customEdgeInsets ??
912921 EdgeInsets .only (
0 commit comments