Merge pull request #52 from DavBfr/master

Add support for asset images
This commit is contained in:
Ian Hickson
2018-12-23 11:04:41 -08:00
committed by GitHub
3 changed files with 16 additions and 2 deletions

View File

@ -26,8 +26,7 @@ design, use the MarkdownRaw class.
## Image support
The `Img` tag only supports the following image locations. It specifically
does not support image locations referring to bundled assets.
The `Img` tag only supports the following image locations:
* From the network: Use a URL prefixed by either `http://` or `https://`.
@ -35,3 +34,6 @@ does not support image locations referring to bundled assets.
concatenating the file name with the path returned by a known storage location,
such as those provided by the [`path_provider`](https://pub.dartlang.org/packages/path_provider)
plugin.
* From image locations referring to bundled assets: Use an asset name prefixed by `resource:`.
like `resource:assets/image.png`.

View File

@ -262,6 +262,8 @@ class MarkdownBuilder implements md.NodeVisitor {
child = new Image.network(uri.toString(), width: width, height: height);
} else if (uri.scheme == 'data') {
child = _handleDataSchemeUri(uri, width, height);
} else if (uri.scheme == "resource") {
child = new Image.asset(path.substring(9), width: width, height: height);
} else {
String filePath = (imageDirectory == null
? uri.toFilePath()

View File

@ -217,6 +217,16 @@ void main() {
expect(image.image is FileImage, isTrue);
});
testWidgets('should work with resources', (WidgetTester tester) async {
await tester.pumpWidget(_boilerplate(
const Markdown(data: '![alt](resource:assets/logo.png)')));
final Image image =
tester.allWidgets.firstWhere((Widget widget) => widget is Image);
expect(image.image is AssetImage, isTrue);
expect((image.image as AssetImage).assetName == 'assets/logo.png', isTrue);
});
testWidgets('should work with local image files', (WidgetTester tester) async {
await tester
.pumpWidget(_boilerplate(const Markdown(data: '![alt](img.png#50x50)')));