Skip to content

Commit

Permalink
Add fillWidth option for wrap content behavior
Browse files Browse the repository at this point in the history
Defaults to true to make it a non-breaking change.
Fixes Sub6Resources#75.
  • Loading branch information
Wilko Manger authored and nvbln committed May 8, 2019
1 parent f8cb452 commit c22ec19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
leadingChar.isNotEmpty ? Text(leadingChar) : Container(),
Expanded(child: child),
Flexible(child: child),
],
));
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -286,6 +286,7 @@ class HtmlRichTextParser extends StatelessWidget {
});

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
);
}
Expand Down

0 comments on commit c22ec19

Please sign in to comment.