Skip to content

Commit

Permalink
change parse to tryParse in image width. Fixes #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Sub6Resources committed Sep 6, 2019
1 parent 38a7739 commit c5278bb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.11.0] - September 6, 2019:

* Make it so `width=100%` doesn't throw error. Fixes [#118](https://github.com/Sub6Resources/flutter_html/issues/118).

## [0.10.4] - June 22, 2019:

* Add support for `customTextStyle` to block and specialty HTML elements.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A Flutter widget for rendering static html tags as Flutter widgets. (Will render
Add the following to your `pubspec.yaml` file:

dependencies:
flutter_html: ^0.10.4
flutter_html: ^0.11.0

## Currently Supported HTML Tags:
`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`
Expand Down
32 changes: 16 additions & 16 deletions lib/rich_text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,18 @@ class HtmlRichTextParser extends StatelessWidget {
case "img":
if (showImages) {
if (node.attributes['src'] != null) {

final width = imageProperties?.width ??
((node.attributes['width'] != null)
? double.tryParse(node.attributes['width'])
: null
);
final height = imageProperties?.height ??
((node.attributes['height'] != null)
? double.tryParse(node.attributes['height'])
: null
);

if (node.attributes['src'].startsWith("data:image") &&
node.attributes['src'].contains("base64,")) {
precacheImage(
Expand All @@ -747,14 +759,8 @@ class HtmlRichTextParser extends StatelessWidget {
child: Image.memory(
base64.decode(
node.attributes['src'].split("base64,")[1].trim()),
width: imageProperties?.width ??
((node.attributes['width'] != null)
? double.tryParse(node.attributes['width'])
: null),
height: imageProperties?.height ??
((node.attributes['height'] != null)
? double.tryParse(node.attributes['height'])
: null),
width: width,
height: height,
scale: imageProperties?.scale ?? 1.0,
matchTextDirection:
imageProperties?.matchTextDirection ?? false,
Expand Down Expand Up @@ -787,14 +793,8 @@ class HtmlRichTextParser extends StatelessWidget {
parseContext.rootWidgetList.add(GestureDetector(
child: Image.network(
node.attributes['src'],
width: imageProperties?.width ??
((node.attributes['width'] != null)
? double.parse(node.attributes['width'])
: null),
height: imageProperties?.height ??
((node.attributes['height'] != null)
? double.parse(node.attributes['height'])
: null),
width: width,
height: height,
scale: imageProperties?.scale ?? 1.0,
matchTextDirection:
imageProperties?.matchTextDirection ?? false,
Expand Down
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.2.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -80,14 +80,14 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
version: "1.7.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -134,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
version: "0.2.5"
typed_data:
dependency: transitive
description:
Expand All @@ -150,5 +150,5 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.2.0 <3.0.0"
dart: ">=2.2.2 <3.0.0"
flutter: ">=0.5.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_html
description: A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!)
version: 0.10.4
version: 0.11.0
author: Matthew Whitaker <[email protected]>
homepage: https://github.com/Sub6Resources/flutter_html

Expand Down

0 comments on commit c5278bb

Please sign in to comment.