From 38006db7b688917eb30d171e2ca406773e94d4bd Mon Sep 17 00:00:00 2001 From: "Nami.W" Date: Thu, 19 Sep 2019 21:12:34 +0800 Subject: [PATCH] asset support for --- lib/rich_text_parser.dart | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lib/rich_text_parser.dart b/lib/rich_text_parser.dart index 25258e2ae1..e842b808fd 100644 --- a/lib/rich_text_parser.dart +++ b/lib/rich_text_parser.dart @@ -787,6 +787,59 @@ class HtmlRichTextParser extends StatelessWidget { } }, )); + } else if (node.attributes['src'].startsWith('asset:')) { + final assetPath = node.attributes['src'].replaceFirst('asset:', ''); + precacheImage( + AssetImage(assetPath), + buildContext, + onError: onImageError ?? (_, __) {}, + ); + parseContext.rootWidgetList.add(GestureDetector( + child: Image.asset( + assetPath, + frameBuilder: (context, child, frame, _) { + if (node.attributes['alt'] != null && frame == null) { + return BlockText( + child: RichText( + textAlign: TextAlign.center, + text: TextSpan( + text: node.attributes['alt'], + style: nextContext.childStyle, + ), + ), + shrinkToFit: shrinkToFit, + ); + } + if (frame != null) { + return child; + } + return Container(); + }, + width: (width ?? -1) > 0 ? width : null, + height: (height ?? -1) > 0 ? height : null, + scale: imageProperties?.scale ?? 1.0, + matchTextDirection: + imageProperties?.matchTextDirection ?? false, + centerSlice: imageProperties?.centerSlice, + filterQuality: + imageProperties?.filterQuality ?? FilterQuality.low, + alignment: imageProperties?.alignment ?? Alignment.center, + colorBlendMode: imageProperties?.colorBlendMode, + fit: imageProperties?.fit, + color: imageProperties?.color, + repeat: imageProperties?.repeat ?? ImageRepeat.noRepeat, + semanticLabel: imageProperties?.semanticLabel, + excludeFromSemantics: + (imageProperties?.semanticLabel == null) + ? true + : false, + ), + onTap: () { + if (onImageTap != null) { + onImageTap(node.attributes['src']); + } + }, + )); } else { precacheImage( NetworkImage(node.attributes['src']),