diff --git a/lib/flutter_html.dart b/lib/flutter_html.dart
index ab3ec5ad0d..9c9d4c78a2 100644
--- a/lib/flutter_html.dart
+++ b/lib/flutter_html.dart
@@ -11,6 +11,7 @@ class Html extends StatelessWidget {
this.backgroundColor,
this.defaultTextStyle,
this.onLinkTap,
+ this.fillWidth = true,
this.renderNewlines = false,
this.customRender,
this.blockSpacing = 14.0,
@@ -26,6 +27,7 @@ class Html extends StatelessWidget {
final Color backgroundColor;
final TextStyle defaultTextStyle;
final OnLinkTap onLinkTap;
+ final bool fillWidth;
final bool renderNewlines;
final double blockSpacing;
final bool useRichText;
@@ -42,12 +44,11 @@ class Html extends StatelessWidget {
return Container(
padding: padding,
color: backgroundColor,
- width: width,
+ width: fillWidth ? width : null,
child: DefaultTextStyle.merge(
style: defaultTextStyle ?? DefaultTextStyle.of(context).style,
child: (useRichText)
? HtmlRichTextParser(
- width: width,
onLinkTap: onLinkTap,
renderNewlines: renderNewlines,
html: data,
diff --git a/lib/html_parser.dart b/lib/html_parser.dart
index 1b4b944165..870e3b31fb 100644
--- a/lib/html_parser.dart
+++ b/lib/html_parser.dart
@@ -84,15 +84,15 @@ class BlockText extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
- width: double.infinity,
padding: this.padding,
margin: this.margin,
decoration: this.decoration,
child: Row(
+ mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
leadingChar.isNotEmpty ? Text(leadingChar) : Container(),
- Expanded(child: child),
+ Flexible(child: child),
],
));
}
@@ -140,9 +140,9 @@ class ParseContext {
class HtmlRichTextParser extends StatelessWidget {
HtmlRichTextParser({
- @required this.width,
this.onLinkTap,
this.renderNewlines = false,
+ this.fillWidth = true,
this.html,
this.linkStyle = const TextStyle(
decoration: TextDecoration.underline,
@@ -152,9 +152,9 @@ class HtmlRichTextParser extends StatelessWidget {
final double indentSize = 10.0;
- final double width;
final onLinkTap;
final bool renderNewlines;
+ final bool fillWidth;
final String html;
final TextStyle linkStyle;
@@ -286,6 +286,7 @@ class HtmlRichTextParser extends StatelessWidget {
});
return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
children: children,
);
}