Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fillWidth option for wrap content behavior #83

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Html extends StatelessWidget {
this.backgroundColor,
this.defaultTextStyle,
this.onLinkTap,
this.fillWidth = true,
this.horizontalAlignment = CrossAxisAlignment.center,
this.renderNewlines = false,
this.customRender,
this.customEdgeInsets,
Expand All @@ -35,6 +37,8 @@ class Html extends StatelessWidget {
final Color backgroundColor;
final TextStyle defaultTextStyle;
final OnLinkTap onLinkTap;
final bool fillWidth;
final CrossAxisAlignment horizontalAlignment;
final bool renderNewlines;
final double blockSpacing;
final bool useRichText;
Expand All @@ -60,12 +64,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,
customEdgeInsets: customEdgeInsets,
Expand All @@ -74,6 +77,7 @@ class Html extends StatelessWidget {
html: data,
onImageError: onImageError,
linkStyle: linkStyle,
horizontalAlignment: horizontalAlignment,
imageProperties: imageProperties,
onImageTap: onImageTap,
showImages: showImages,
Expand Down
5 changes: 3 additions & 2 deletions lib/rich_text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class ParseContext {

class HtmlRichTextParser extends StatelessWidget {
HtmlRichTextParser({
@required this.width,
this.onLinkTap,
this.renderNewlines = false,
this.html,
Expand All @@ -171,11 +170,11 @@ class HtmlRichTextParser extends StatelessWidget {
this.imageProperties,
this.onImageTap,
this.showImages = true,
this.horizontalAlignment = CrossAxisAlignment.center,
});

final double indentSize = 10.0;

final double width;
final onLinkTap;
final bool renderNewlines;
final String html;
Expand All @@ -187,6 +186,7 @@ class HtmlRichTextParser extends StatelessWidget {
final ImageProperties imageProperties;
final OnImageTap onImageTap;
final bool showImages;
final CrossAxisAlignment horizontalAlignment;

// style elements set a default style
// for all child nodes
Expand Down Expand Up @@ -338,6 +338,7 @@ class HtmlRichTextParser extends StatelessWidget {
});

return Column(
crossAxisAlignment: horizontalAlignment,
children: children,
);
}
Expand Down