mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
AssetImage.obtainKey handles devicePixelRatio == null (#12564)
This commit is contained in:
parent
9ce3ba314e
commit
bd3e91ed98
@ -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 @@
|
|||||||
// 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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user