mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 09:38:17 +08:00
@ -26,8 +26,7 @@ design, use the MarkdownRaw class.
|
|||||||
|
|
||||||
## Image support
|
## Image support
|
||||||
|
|
||||||
The `Img` tag only supports the following image locations. It specifically
|
The `Img` tag only supports the following image locations:
|
||||||
does not support image locations referring to bundled assets.
|
|
||||||
|
|
||||||
* From the network: Use a URL prefixed by either `http://` or `https://`.
|
* 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,
|
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)
|
such as those provided by the [`path_provider`](https://pub.dartlang.org/packages/path_provider)
|
||||||
plugin.
|
plugin.
|
||||||
|
|
||||||
|
* From image locations referring to bundled assets: Use an asset name prefixed by `resource:`.
|
||||||
|
like `resource:assets/image.png`.
|
||||||
|
@ -262,6 +262,8 @@ class MarkdownBuilder implements md.NodeVisitor {
|
|||||||
child = new Image.network(uri.toString(), width: width, height: height);
|
child = new Image.network(uri.toString(), width: width, height: height);
|
||||||
} else if (uri.scheme == 'data') {
|
} else if (uri.scheme == 'data') {
|
||||||
child = _handleDataSchemeUri(uri, width, height);
|
child = _handleDataSchemeUri(uri, width, height);
|
||||||
|
} else if (uri.scheme == "resource") {
|
||||||
|
child = new Image.asset(path.substring(9), width: width, height: height);
|
||||||
} else {
|
} else {
|
||||||
String filePath = (imageDirectory == null
|
String filePath = (imageDirectory == null
|
||||||
? uri.toFilePath()
|
? uri.toFilePath()
|
||||||
|
@ -217,6 +217,16 @@ void main() {
|
|||||||
expect(image.image is FileImage, isTrue);
|
expect(image.image is FileImage, isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('should work with resources', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
const Markdown(data: '')));
|
||||||
|
|
||||||
|
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 {
|
testWidgets('should work with local image files', (WidgetTester tester) async {
|
||||||
await tester
|
await tester
|
||||||
.pumpWidget(_boilerplate(const Markdown(data: '')));
|
.pumpWidget(_boilerplate(const Markdown(data: '')));
|
||||||
|
Reference in New Issue
Block a user