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

This commit is contained in:
Hans Muller 2017-10-17 09:27:04 -07:00 committed by GitHub
parent 9ce3ba314e
commit bd3e91ed98
2 changed files with 13 additions and 1 deletions

View File

@ -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>();

View File

@ -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 {
@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() {
} }
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);
});
} }