File tree Expand file tree Collapse file tree
packages/flutter_markdown Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,12 +26,14 @@ design, use the MarkdownRaw class.
2626
2727## Image support
2828
29- The ` Img ` tag only supports the following image locations. It specifically
30- does not support image locations referring to bundled assets.
29+ The ` Img ` tag only supports the following image locations:
3130
3231* From the network: Use a URL prefixed by either ` http:// ` or ` https:// ` .
3332
3433* From local files on the device: Use an absolute path to the file, for example by
3534 concatenating the file name with the path returned by a known storage location,
3635 such as those provided by the [ ` path_provider ` ] ( https://pub.dartlang.org/packages/path_provider )
3736 plugin.
37+
38+ * From image locations referring to bundled assets: Use an asset name prefixed by ` resource: ` .
39+ like ` resource:assets/image.png ` .
Original file line number Diff line number Diff line change @@ -262,6 +262,8 @@ class MarkdownBuilder implements md.NodeVisitor {
262262 child = new Image .network (uri.toString (), width: width, height: height);
263263 } else if (uri.scheme == 'data' ) {
264264 child = _handleDataSchemeUri (uri, width, height);
265+ } else if (uri.scheme == "resource" ) {
266+ child = new Image .asset (path.substring (9 ), width: width, height: height);
265267 } else {
266268 String filePath = (imageDirectory == null
267269 ? uri.toFilePath ()
Original file line number Diff line number Diff line change @@ -217,6 +217,16 @@ void main() {
217217 expect (image.image is FileImage , isTrue);
218218 });
219219
220+ testWidgets ('should work with resources' , (WidgetTester tester) async {
221+ await tester.pumpWidget (_boilerplate (
222+ const Markdown (data: '' )));
223+
224+ final Image image =
225+ tester.allWidgets.firstWhere ((Widget widget) => widget is Image );
226+ expect (image.image is AssetImage , isTrue);
227+ expect ((image.image as AssetImage ).assetName == 'assets/logo.png' , isTrue);
228+ });
229+
220230 testWidgets ('should work with local image files' , (WidgetTester tester) async {
221231 await tester
222232 .pumpWidget (_boilerplate (const Markdown (data: '' )));
You can’t perform that action at this time.
0 commit comments