Skip to content

Commit

Permalink
asset support for <img>
Browse files Browse the repository at this point in the history
  • Loading branch information
namiwang committed Sep 19, 2019
1 parent 6854229 commit 38006db
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/rich_text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down

0 comments on commit 38006db

Please sign in to comment.