Commit bd3e91ed authored by Hans Muller's avatar Hans Muller Committed by GitHub

AssetImage.obtainKey handles devicePixelRatio == null (#12564)

parent 9ce3ba31
...@@ -218,7 +218,7 @@ class AssetImage extends AssetBundleImageProvider { ...@@ -218,7 +218,7 @@ class AssetImage extends AssetBundleImageProvider {
} }
String _chooseVariant(String main, ImageConfiguration config, List<String> candidates) { String _chooseVariant(String main, ImageConfiguration config, List<String> candidates) {
if (candidates == null || candidates.isEmpty) if (config.devicePixelRatio == null || candidates == null || candidates.isEmpty)
return main; return main;
// TODO(ianh): Consider moving this parsing logic into _manifestParser. // TODO(ianh): Consider moving this parsing logic into _manifestParser.
final SplayTreeMap<double, String> mapping = new SplayTreeMap<double, String>(); final SplayTreeMap<double, String> mapping = new SplayTreeMap<double, String>();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -14,6 +15,9 @@ class TestAssetBundle extends CachingAssetBundle { ...@@ -14,6 +15,9 @@ class TestAssetBundle extends CachingAssetBundle {
@override @override
Future<ByteData> load(String key) async { Future<ByteData> 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; loadCallCount[key] = loadCallCount[key] ?? 0 + 1;
if (key == 'one') if (key == 'one')
return new ByteData(1)..setInt8(0, 49); return new ByteData(1)..setInt8(0, 49);
...@@ -43,4 +47,12 @@ void main() { ...@@ -43,4 +47,12 @@ void main() {
} }
expect(loadException, isFlutterError); 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);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment