Skip to content

Commit 9c056cb

Browse files
Merge branch 'master' into master
2 parents 877fec4 + 03c21aa commit 9c056cb

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: flutter_html
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with a single custom sponsorship URL

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
## [0.10.2] - June 19, 2019:
2+
3+
* Add `customTextAlign` property ([#112](https://github.com/Sub6Resources/flutter_html/pull/112))
4+
* Use `tryParse` instead of `parse` for image width and height attributes so that `%` values are ignored safely. Fixes [#98](https://github.com/Sub6Resources/flutter_html/issues/98)
5+
16
## [0.10.1] - May 20, 2019:
27

38
* Image properties and onImageTap for the richTextParser, plus some fixes ([#90](https://github.com/Sub6Resources/flutter_html/pull/90))
9+
* Hotfix 1 (June 6, 2019): Fixes [#100](https://github.com/Sub6Resources/flutter_html/issues/100)
410

511
## [0.10.0] - May 18, 2019:
612

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!)
66

7+
## Roadmap
8+
[View the development roadmap in the wiki](https://github.com/Sub6Resources/flutter_html/wiki/Roadmap)
9+
710
## Installing:
811

912
Add the following to your `pubspec.yaml` file:
1013

1114
dependencies:
12-
flutter_html: ^0.10.1
15+
flutter_html: ^0.10.2
1316

1417
## Currently Supported HTML Tags:
1518
`a`, `abbr`, `acronym`, `address`, `article`, `aside`, `b`, `bdi`, `bdo`, `big`, `blockquote`, `body`, `br`, `caption`, `cite`, `code`, `data`, `dd`, `del`, `dfn`, `div`, `dl`, `dt`, `em`, `figcaption`, `figure`, `footer`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `header`, `hr`, `i`, `img`, `ins`, `kbd`, `li`, `main`, `mark`, `nav`, `noscript`, `ol`, `p`, `pre`, `q`, `rp`, `rt`, `ruby`, `s`, `samp`, `section`, `small`, `span`, `strike`, `strong`, `sub`, `sup`, `table`, `tbody`, `td`, `template`, `tfoot`, `th`, `thead`, `time`, `tr`, `tt`, `u`, `ul`, `var`
@@ -82,6 +85,14 @@ Check out the official Flutter WebView package here: https://pub.dartlang.org/pa
8285
}
8386
}
8487
},
88+
customTextAlign: (dom.Node node) {
89+
if (node is dom.Element) {
90+
switch (node.localName) {
91+
case "p":
92+
return TextAlign.justify;
93+
}
94+
}
95+
},
8596
)
8697

8798
## `useRichText` parameter

example/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ class _MyHomePageState extends State<MyHomePage> {
137137
}
138138
}
139139
},
140+
customTextAlign: (dom.Node node) {
141+
if (node is dom.Element) {
142+
switch (node.localName) {
143+
case "p":
144+
return TextAlign.justify;
145+
}
146+
}
147+
},
140148
),
141149
),
142150
),

lib/flutter_html.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Html extends StatelessWidget {
1616
this.customRender,
1717
this.customEdgeInsets,
1818
this.customTextStyle,
19+
this.customTextAlign,
1920
this.blockSpacing = 14.0,
2021
this.useRichText = true,
2122
this.onImageError,
@@ -49,6 +50,7 @@ class Html extends StatelessWidget {
4950
final CustomRender customRender;
5051
final CustomEdgeInsets customEdgeInsets;
5152
final CustomTextStyle customTextStyle;
53+
final CustomTextAlign customTextAlign;
5254

5355
@override
5456
Widget build(BuildContext context) {
@@ -67,6 +69,7 @@ class Html extends StatelessWidget {
6769
renderNewlines: renderNewlines,
6870
customEdgeInsets: customEdgeInsets,
6971
customTextStyle: customTextStyle,
72+
customTextAlign: customTextAlign,
7073
html: data,
7174
onImageError: onImageError,
7275
linkStyle: linkStyle,

lib/html_parser.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef CustomTextStyle = TextStyle Function(
1010
dom.Node node,
1111
TextStyle baseStyle,
1212
);
13+
typedef CustomTextAlign = TextAlign Function(dom.Element elem);
1314
typedef CustomEdgeInsets = EdgeInsets Function(dom.Node node);
1415
typedef OnLinkTap = void Function(String url);
1516
typedef OnImageTap = void Function(String source);
@@ -142,8 +143,9 @@ class HtmlRichTextParser extends StatelessWidget {
142143
this.onLinkTap,
143144
this.renderNewlines = false,
144145
this.html,
145-
this.customTextStyle,
146146
this.customEdgeInsets,
147+
this.customTextStyle,
148+
this.customTextAlign,
147149
this.onImageError,
148150
this.linkStyle = const TextStyle(
149151
decoration: TextDecoration.underline,
@@ -161,8 +163,9 @@ class HtmlRichTextParser extends StatelessWidget {
161163
final onLinkTap;
162164
final bool renderNewlines;
163165
final String html;
164-
final CustomTextStyle customTextStyle;
165166
final CustomEdgeInsets customEdgeInsets;
167+
final CustomTextStyle customTextStyle;
168+
final CustomTextAlign customTextAlign;
166169
final ImageErrorListener onImageError;
167170
final TextStyle linkStyle;
168171
final ImageProperties imageProperties;
@@ -305,8 +308,10 @@ class HtmlRichTextParser extends StatelessWidget {
305308
widgetList.forEach((dynamic w) {
306309
if (w is BlockText) {
307310
if (w.child.text == null) return;
308-
if ((w.child.text.text == null || w.child.text.text.isEmpty) &&
309-
(w.child.text.children == null || w.child.text.children.isEmpty)) return;
311+
TextSpan childTextSpan = w.child.text;
312+
if ((childTextSpan.text == null || childTextSpan.text.isEmpty) &&
313+
(childTextSpan.children == null || childTextSpan.children.isEmpty))
314+
return;
310315
} else if (w is LinkBlock) {
311316
if (w.children.isEmpty) return;
312317
} else if (w is LinkTextSpan) {
@@ -661,6 +666,9 @@ class HtmlRichTextParser extends StatelessWidget {
661666
// so if we have a block element, reset the parentElement to null
662667
parseContext.parentElement = null;
663668
TextAlign textAlign = TextAlign.left;
669+
if (customTextAlign != null) {
670+
textAlign = customTextAlign(node) ?? textAlign;
671+
}
664672

665673
EdgeInsets _customEdgeInsets;
666674
if (customEdgeInsets != null) {
@@ -690,11 +698,11 @@ class HtmlRichTextParser extends StatelessWidget {
690698
base64.decode(node.attributes['src'].split("base64,")[1].trim()),
691699
width: imageProperties?.width ??
692700
((node.attributes['width'] != null)
693-
? double.parse(node.attributes['width'])
701+
? double.tryParse(node.attributes['width'])
694702
: null),
695703
height: imageProperties?.height ??
696704
((node.attributes['height'] != null)
697-
? double.parse(node.attributes['height'])
705+
? double.tryParse(node.attributes['height'])
698706
: null),
699707
scale: imageProperties?.scale ?? 1.0,
700708
matchTextDirection: imageProperties?.matchTextDirection ?? false,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_html
22
description: A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!)
3-
version: 0.10.1
3+
version: 0.10.2
44
author: Matthew Whitaker <sub6resources@gmail.com>
55
homepage: https://github.com/Sub6Resources/flutter_html
66

0 commit comments

Comments
 (0)