Skip to content

Commit c5278bb

Browse files
committed
change parse to tryParse in image width. Fixes Sub6Resources#118
1 parent 38a7739 commit c5278bb

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.11.0] - September 6, 2019:
2+
3+
* Make it so `width=100%` doesn't throw error. Fixes [#118](https://github.com/Sub6Resources/flutter_html/issues/118).
4+
15
## [0.10.4] - June 22, 2019:
26

37
* Add support for `customTextStyle` to block and specialty HTML elements.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A Flutter widget for rendering static html tags as Flutter widgets. (Will render
1212
Add the following to your `pubspec.yaml` file:
1313

1414
dependencies:
15-
flutter_html: ^0.10.4
15+
flutter_html: ^0.11.0
1616

1717
## Currently Supported HTML Tags:
1818
`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`

lib/rich_text_parser.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,18 @@ class HtmlRichTextParser extends StatelessWidget {
732732
case "img":
733733
if (showImages) {
734734
if (node.attributes['src'] != null) {
735+
736+
final width = imageProperties?.width ??
737+
((node.attributes['width'] != null)
738+
? double.tryParse(node.attributes['width'])
739+
: null
740+
);
741+
final height = imageProperties?.height ??
742+
((node.attributes['height'] != null)
743+
? double.tryParse(node.attributes['height'])
744+
: null
745+
);
746+
735747
if (node.attributes['src'].startsWith("data:image") &&
736748
node.attributes['src'].contains("base64,")) {
737749
precacheImage(
@@ -747,14 +759,8 @@ class HtmlRichTextParser extends StatelessWidget {
747759
child: Image.memory(
748760
base64.decode(
749761
node.attributes['src'].split("base64,")[1].trim()),
750-
width: imageProperties?.width ??
751-
((node.attributes['width'] != null)
752-
? double.tryParse(node.attributes['width'])
753-
: null),
754-
height: imageProperties?.height ??
755-
((node.attributes['height'] != null)
756-
? double.tryParse(node.attributes['height'])
757-
: null),
762+
width: width,
763+
height: height,
758764
scale: imageProperties?.scale ?? 1.0,
759765
matchTextDirection:
760766
imageProperties?.matchTextDirection ?? false,
@@ -787,14 +793,8 @@ class HtmlRichTextParser extends StatelessWidget {
787793
parseContext.rootWidgetList.add(GestureDetector(
788794
child: Image.network(
789795
node.attributes['src'],
790-
width: imageProperties?.width ??
791-
((node.attributes['width'] != null)
792-
? double.parse(node.attributes['width'])
793-
: null),
794-
height: imageProperties?.height ??
795-
((node.attributes['height'] != null)
796-
? double.parse(node.attributes['height'])
797-
: null),
796+
width: width,
797+
height: height,
798798
scale: imageProperties?.scale ?? 1.0,
799799
matchTextDirection:
800800
imageProperties?.matchTextDirection ?? false,

pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Generated by pub
2-
# See https://www.dartlang.org/tools/pub/glossary#lockfile
2+
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
44
async:
55
dependency: transitive
66
description:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.1.0"
10+
version: "2.2.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -80,14 +80,14 @@ packages:
8080
name: pedantic
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "1.5.0"
83+
version: "1.7.0"
8484
quiver:
8585
dependency: transitive
8686
description:
8787
name: quiver
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "2.0.2"
90+
version: "2.0.3"
9191
sky_engine:
9292
dependency: transitive
9393
description: flutter
@@ -134,7 +134,7 @@ packages:
134134
name: test_api
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "0.2.4"
137+
version: "0.2.5"
138138
typed_data:
139139
dependency: transitive
140140
description:
@@ -150,5 +150,5 @@ packages:
150150
source: hosted
151151
version: "2.0.8"
152152
sdks:
153-
dart: ">=2.2.0 <3.0.0"
153+
dart: ">=2.2.2 <3.0.0"
154154
flutter: ">=0.5.0"

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.4
3+
version: 0.11.0
44
author: Matthew Whitaker <sub6resources@gmail.com>
55
homepage: https://github.com/Sub6Resources/flutter_html
66

0 commit comments

Comments
 (0)