Skip to content

Commit db68e21

Browse files
committed
Fix shrink wrap not applying correctly
1 parent f24f461 commit db68e21

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/html_parser.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class HtmlParser extends StatelessWidget {
7878
textSpan: parsedTree,
7979
style: cleanedTree.style,
8080
textScaleFactor: MediaQuery.of(context).textScaleFactor,
81+
renderContext: RenderContext(
82+
buildContext: context,
83+
parser: this,
84+
style: Style.fromTextStyle(Theme.of(context).textTheme.bodyText2),
85+
),
8186
);
8287
}
8388

@@ -319,6 +324,7 @@ class HtmlParser extends StatelessWidget {
319324
style: newContext.style.generateTextStyle(),
320325
),
321326
style: newContext.style,
327+
renderContext: context,
322328
),
323329
)
324330
],
@@ -409,6 +415,7 @@ class HtmlParser extends StatelessWidget {
409415
[],
410416
),
411417
style: newContext.style,
418+
renderContext: context,
412419
),
413420
),
414421
);
@@ -757,6 +764,7 @@ class ContainerSpan extends StatelessWidget {
757764
children: children,
758765
),
759766
style: newContext.style,
767+
renderContext: newContext,
760768
),
761769
);
762770
}
@@ -766,20 +774,20 @@ class StyledText extends StatelessWidget {
766774
final InlineSpan textSpan;
767775
final Style style;
768776
final double textScaleFactor;
777+
final RenderContext renderContext;
769778

770779
const StyledText({
771780
this.textSpan,
772781
this.style,
773782
this.textScaleFactor = 1.0,
783+
this.renderContext,
774784
});
775785

776786
@override
777787
Widget build(BuildContext context) {
778788
return SizedBox(
779-
width:
780-
style.display == Display.BLOCK || style.display == Display.LIST_ITEM
781-
? double.infinity
782-
: null,
789+
width: (style.display == Display.BLOCK || style.display == Display.LIST_ITEM) && renderContext.parser.shrinkWrap != true
790+
? double.infinity : renderContext.parser.shrinkWrap == true ? MediaQuery.of(renderContext.buildContext).size.width : null,
783791
child: Text.rich(
784792
textSpan,
785793
style: style.generateTextStyle(),

lib/src/layout_element.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class TableLayoutElement extends LayoutElement {
119119
child: StyledText(
120120
textSpan: context.parser.parseTree(context, child),
121121
style: child.style,
122+
renderContext: context,
122123
),
123124
),
124125
),

0 commit comments

Comments
 (0)