Skip to content

Commit bed7cc6

Browse files
committed
Add support for asset images to the new parser
1 parent b6987e3 commit bed7cc6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/src/replaced_element.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,34 @@ class ImageContentElement extends ReplacedElement {
7474

7575
@override
7676
Widget toWidget(RenderContext context) {
77-
if (src == null)
77+
if (src == null) {
7878
return Text(alt ?? "", style: context.style.generateTextStyle());
79-
if (src.startsWith("data:image") && src.contains("base64,")) {
79+
} else if (src.startsWith("data:image") && src.contains("base64,")) {
8080
return Image.memory(base64.decode(src.split("base64,")[1].trim()));
81+
} else if(src.startsWith("asset:")) {
82+
final assetPath = src.replaceFirst('asset:', '');
83+
//TODO precache image
84+
return Image.asset(
85+
assetPath,
86+
frameBuilder: (ctx, child, frame, _) {
87+
if(frame == null) {
88+
return Text(alt ?? "", style: context.style.generateTextStyle());
89+
}
90+
return child;
91+
},
92+
);
8193
} else {
94+
//TODO precache image
8295
return Image.network(
8396
src,
84-
frameBuilder: (ctx, child, frame, something) {
97+
frameBuilder: (ctx, child, frame, _) {
8598
if (frame == null) {
8699
return Text(alt ?? "", style: context.style.generateTextStyle());
87100
}
88-
89101
return child;
90102
},
91103
);
92104
}
93-
//TODO(Sub6Resources): precacheImage
94105
}
95106
}
96107

0 commit comments

Comments
 (0)