@@ -83,31 +83,25 @@ class BlockText extends StatelessWidget {
83
83
final RichText child;
84
84
final EdgeInsets padding;
85
85
final EdgeInsets margin;
86
- final String leadingChar;
87
86
final Decoration decoration;
87
+ final bool shrinkToFit;
88
88
89
89
BlockText ({
90
90
@required this .child,
91
+ @required this .shrinkToFit,
91
92
this .padding,
92
93
this .margin,
93
- this .leadingChar = '' ,
94
94
this .decoration,
95
95
});
96
96
97
97
@override
98
98
Widget build (BuildContext context) {
99
99
return Container (
100
- width: double .infinity,
100
+ width: shrinkToFit ? null : double .infinity,
101
101
padding: this .padding,
102
102
margin: this .margin,
103
103
decoration: this .decoration,
104
- child: Row (
105
- crossAxisAlignment: CrossAxisAlignment .start,
106
- children: < Widget > [
107
- leadingChar.isNotEmpty ? Text (leadingChar) : Container (),
108
- Expanded (child: child),
109
- ],
110
- ),
104
+ child: child,
111
105
);
112
106
}
113
107
}
@@ -155,7 +149,7 @@ class ParseContext {
155
149
156
150
class HtmlRichTextParser extends StatelessWidget {
157
151
HtmlRichTextParser ({
158
- @required this .width ,
152
+ this .shrinkToFit ,
159
153
this .onLinkTap,
160
154
this .renderNewlines = false ,
161
155
this .html,
@@ -175,7 +169,7 @@ class HtmlRichTextParser extends StatelessWidget {
175
169
176
170
final double indentSize = 10.0 ;
177
171
178
- final double width ;
172
+ final bool shrinkToFit ;
179
173
final onLinkTap;
180
174
final bool renderNewlines;
181
175
final String html;
@@ -426,6 +420,7 @@ class HtmlRichTextParser extends StatelessWidget {
426
420
));
427
421
}
428
422
BlockText blockText = BlockText (
423
+ shrinkToFit: shrinkToFit,
429
424
margin: EdgeInsets .only (
430
425
top: 8.0 ,
431
426
bottom: 8.0 ,
@@ -439,8 +434,10 @@ class HtmlRichTextParser extends StatelessWidget {
439
434
);
440
435
parseContext.rootWidgetList.add (blockText);
441
436
} else {
442
- parseContext.rootWidgetList
443
- .add (BlockText (child: RichText (text: span)));
437
+ parseContext.rootWidgetList.add (BlockText (
438
+ child: RichText (text: span),
439
+ shrinkToFit: shrinkToFit,
440
+ ));
444
441
}
445
442
446
443
// this allows future items to be added as children of this item
@@ -607,6 +604,7 @@ class HtmlRichTextParser extends StatelessWidget {
607
604
} else {
608
605
// start a new block element for this link and its text
609
606
BlockText blockElement = BlockText (
607
+ shrinkToFit: shrinkToFit,
610
608
margin: EdgeInsets .only (
611
609
left: parseContext.indentLevel * indentSize, top: 10.0 ),
612
610
child: RichText (text: span),
@@ -856,16 +854,18 @@ class HtmlRichTextParser extends StatelessWidget {
856
854
leadingChar = parseContext.listCount.toString () + '.' ;
857
855
}
858
856
BlockText blockText = BlockText (
857
+ shrinkToFit: shrinkToFit,
859
858
margin: EdgeInsets .only (
860
859
left: parseContext.indentLevel * indentSize, top: 3.0 ),
861
860
child: RichText (
862
861
text: TextSpan (
863
- text: '' ,
864
- style: nextContext.childStyle,
865
- children: < TextSpan > [],
862
+ text: '$leadingChar ' ,
863
+ style: DefaultTextStyle .of (buildContext).style,
864
+ children: < TextSpan > [
865
+ TextSpan (text: '' , style: nextContext.childStyle)
866
+ ],
866
867
),
867
868
),
868
- leadingChar: '$leadingChar ' ,
869
869
);
870
870
parseContext.rootWidgetList.add (blockText);
871
871
nextContext.parentElement = blockText.child.text;
@@ -926,6 +926,7 @@ class HtmlRichTextParser extends StatelessWidget {
926
926
));
927
927
}
928
928
BlockText blockText = BlockText (
929
+ shrinkToFit: shrinkToFit,
929
930
margin: node.localName != 'body'
930
931
? _customEdgeInsets ??
931
932
EdgeInsets .only (
0 commit comments