Skip to content

Commit 42b07c0

Browse files
committed
Version 0.9.3 - Add support for base64 encoded images
1 parent 1f3d137 commit 42b07c0

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.9.3] - January 31, 2019:
2+
3+
* Adds support for base64 encoded images
4+
15
## [0.9.2] - January 31, 2019:
26

37
* Adds partial support for deprecated `font` tag.

README.md

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

1010
dependencies:
11-
flutter_html: ^0.9.2
11+
flutter_html: ^0.9.3
1212

1313
## Currently Supported HTML Tags:
1414
`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/html_parser.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter/gestures.dart';
35
import 'package:html/parser.dart' as parser;
@@ -571,8 +573,13 @@ class HtmlRichTextParser extends StatelessWidget {
571573
break;
572574
case "img":
573575
if (node.attributes['src'] != null) {
574-
parseContext.rootWidgetList
575-
.add(Image.network(node.attributes['src']));
576+
if(node.attributes['src'].startsWith("data:image") && node.attributes['src'].contains("base64,")) {
577+
parseContext.rootWidgetList
578+
.add(Image.memory(base64.decode(node.attributes['src'].split("base64,")[1].trim())));
579+
} else {
580+
parseContext.rootWidgetList
581+
.add(Image.network(node.attributes['src']));
582+
}
576583
} else if (node.attributes['alt'] != null) {
577584
parseContext.rootWidgetList.add(BlockText(
578585
margin: EdgeInsets.symmetric(horizontal: 0.0, vertical: 10.0),
@@ -1236,6 +1243,9 @@ class HtmlOldParser extends StatelessWidget {
12361243
);
12371244
case "img":
12381245
if (node.attributes['src'] != null) {
1246+
if(node.attributes['src'].startsWith("data:image") && node.attributes['src'].contains("base64,")) {
1247+
return Image.memory(base64.decode(node.attributes['src'].split("base64,")[1].trim()));
1248+
}
12391249
return Image.network(node.attributes['src']);
12401250
} else if (node.attributes['alt'] != null) {
12411251
//Temp fix for https://github.com/flutter/flutter/issues/736

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

0 commit comments

Comments
 (0)