Skip to content

Commit

Permalink
Merge pull request #112 from GeertJohan/feature/custom-text-alignment
Browse files Browse the repository at this point in the history
Add support for custom text alignment
  • Loading branch information
Sub6Resources authored Jun 20, 2019
2 parents 0127603 + e65013a commit 97a671b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Html extends StatelessWidget {
this.customRender,
this.customEdgeInsets,
this.customTextStyle,
this.customTextAlign,
this.blockSpacing = 14.0,
this.useRichText = true,
this.onImageError,
Expand Down Expand Up @@ -49,6 +50,7 @@ class Html extends StatelessWidget {
final CustomRender customRender;
final CustomEdgeInsets customEdgeInsets;
final CustomTextStyle customTextStyle;
final CustomTextAlign customTextAlign;

@override
Widget build(BuildContext context) {
Expand All @@ -67,6 +69,7 @@ class Html extends StatelessWidget {
renderNewlines: renderNewlines,
customEdgeInsets: customEdgeInsets,
customTextStyle: customTextStyle,
customTextAlign: customTextAlign,
html: data,
onImageError: onImageError,
linkStyle: linkStyle,
Expand Down
10 changes: 8 additions & 2 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef CustomTextStyle = TextStyle Function(
dom.Node node,
TextStyle baseStyle,
);
typedef CustomTextAlign = TextAlign Function(dom.Element elem);
typedef CustomEdgeInsets = EdgeInsets Function(dom.Node node);
typedef OnLinkTap = void Function(String url);
typedef OnImageTap = void Function();
Expand Down Expand Up @@ -150,8 +151,9 @@ class HtmlRichTextParser extends StatelessWidget {
this.onLinkTap,
this.renderNewlines = false,
this.html,
this.customTextStyle,
this.customEdgeInsets,
this.customTextStyle,
this.customTextAlign,
this.onImageError,
this.linkStyle = const TextStyle(
decoration: TextDecoration.underline,
Expand All @@ -169,8 +171,9 @@ class HtmlRichTextParser extends StatelessWidget {
final onLinkTap;
final bool renderNewlines;
final String html;
final CustomTextStyle customTextStyle;
final CustomEdgeInsets customEdgeInsets;
final CustomTextStyle customTextStyle;
final CustomTextAlign customTextAlign;
final ImageErrorListener onImageError;
final TextStyle linkStyle;
final ImageProperties imageProperties;
Expand Down Expand Up @@ -696,6 +699,9 @@ class HtmlRichTextParser extends StatelessWidget {
// so if we have a block element, reset the parentElement to null
parseContext.parentElement = null;
TextAlign textAlign = TextAlign.left;
if (customTextAlign != null) {
textAlign = customTextAlign(node) ?? textAlign;
}

EdgeInsets _customEdgeInsets;
if (customEdgeInsets != null) {
Expand Down

0 comments on commit 97a671b

Please sign in to comment.