diff --git a/packages/flutter/lib/src/services/asset_bundle.dart b/packages/flutter/lib/src/services/asset_bundle.dart index 866aaba173..23a76dc44d 100644 --- a/packages/flutter/lib/src/services/asset_bundle.dart +++ b/packages/flutter/lib/src/services/asset_bundle.dart @@ -43,15 +43,17 @@ class NetworkAssetBundle extends AssetBundle { } abstract class CachingAssetBundle extends AssetBundle { - Map imageCache = new Map(); - Map> _stringCache = new Map>(); + final Map imageResourceCache = + new Map(); + final Map> _stringCache = + new Map>(); Future fetchImage(String key) async { return await decodeImageFromDataPipe(await load(key)); } ImageResource loadImage(String key) { - return imageCache.putIfAbsent(key, () { + return imageResourceCache.putIfAbsent(key, () { return new ImageResource(fetchImage(key)); }); } diff --git a/packages/flutter/lib/src/widgets/asset_vendor.dart b/packages/flutter/lib/src/widgets/asset_vendor.dart index e005381aed..96f902eb6f 100644 --- a/packages/flutter/lib/src/widgets/asset_vendor.dart +++ b/packages/flutter/lib/src/widgets/asset_vendor.dart @@ -30,7 +30,7 @@ class _ResolvingAssetBundle extends CachingAssetBundle { final AssetBundle bundle; final _AssetResolver resolver; - Map keyCache = {}; + final Map keyCache = {}; Future load(String key) async { if (!keyCache.containsKey(key)) @@ -56,7 +56,7 @@ class _ResolutionAwareAssetBundle extends _ResolvingAssetBundle { // At this point the key should be in our key cache, and the image // resource should be in our image cache double scale = resolver.getScale(keyCache[key]); - this.imageCache[key].scale = scale; + imageResourceCache[key].scale = scale; return await decodeImageFromDataPipe(pipe); } } @@ -110,9 +110,8 @@ class _ResolutionAwareAssetResolver extends _VariantAssetResolver { double getScale(String key) { Match match = _extractRatioRegExp.firstMatch(key); - if (match != null && match.groupCount > 0) { + if (match != null && match.groupCount > 0) return double.parse(match.group(1)); - } return 1.0; } @@ -134,9 +133,8 @@ class _ResolutionAwareAssetResolver extends _VariantAssetResolver { String chooseVariant(String main, List candidates) { SplayTreeMap mapping = new SplayTreeMap(); - for (String candidate in candidates) { + for (String candidate in candidates) mapping[getScale(candidate)] = candidate; - } mapping[_naturalResolution] = main; return _findNearest(mapping, devicePixelRatio); }