diff --git a/packages/flutter/lib/src/services/image_resolution.dart b/packages/flutter/lib/src/services/image_resolution.dart index e0e605f4106..a6f741a7b48 100644 --- a/packages/flutter/lib/src/services/image_resolution.dart +++ b/packages/flutter/lib/src/services/image_resolution.dart @@ -218,7 +218,7 @@ class AssetImage extends AssetBundleImageProvider { } String _chooseVariant(String main, ImageConfiguration config, List candidates) { - if (candidates == null || candidates.isEmpty) + if (config.devicePixelRatio == null || candidates == null || candidates.isEmpty) return main; // TODO(ianh): Consider moving this parsing logic into _manifestParser. final SplayTreeMap mapping = new SplayTreeMap(); diff --git a/packages/flutter/test/services/asset_bundle_test.dart b/packages/flutter/test/services/asset_bundle_test.dart index 34821fb2062..8ca6313f767 100644 --- a/packages/flutter/test/services/asset_bundle_test.dart +++ b/packages/flutter/test/services/asset_bundle_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:convert'; import 'dart:typed_data'; import 'package:flutter/foundation.dart'; @@ -14,6 +15,9 @@ class TestAssetBundle extends CachingAssetBundle { @override Future load(String key) async { + if (key == 'AssetManifest.json') + return new ByteData.view(new Uint8List.fromList(const Utf8Encoder().convert('{"one": ["one"]}')).buffer); + loadCallCount[key] = loadCallCount[key] ?? 0 + 1; if (key == 'one') return new ByteData(1)..setInt8(0, 49); @@ -43,4 +47,12 @@ void main() { } expect(loadException, isFlutterError); }); + + test('AssetImage.obtainKey succeeds with ImageConfiguration.empty', () async { + // This is a regression test for https://github.com/flutter/flutter/issues/12392 + final AssetImage assetImage = new AssetImage('one', bundle: new TestAssetBundle()); + final AssetBundleImageKey key = await assetImage.obtainKey(ImageConfiguration.empty); + expect(key.name, 'one'); + expect(key.scale, 1.0); + }); }