Commit 5161d120 authored by Kris Giesing's avatar Kris Giesing

Give scale parameter to ImageCache and NetworkImage

parent d4cc315c
......@@ -78,7 +78,7 @@ class RenderImage extends RenderBox {
markNeedsLayout();
}
/// If non-null, specify the image's scale.
/// Specifies the image's scale.
///
/// Used when determining the best display size for the image.
double get scale => _scale;
......
......@@ -43,9 +43,9 @@ class NetworkAssetBundle extends AssetBundle {
abstract class CachingAssetBundle extends AssetBundle {
final Map<String, ImageResource> imageResourceCache =
new Map<String, ImageResource>();
<String, ImageResource>{};
final Map<String, Future<String>> _stringCache =
new Map<String, Future<String>>();
<String, Future<String>>{};
Future<ImageInfo> fetchImage(String key) async {
return new ImageInfo(image: await decodeImageFromDataPipe(await load(key)));
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:ui' show hashValues;
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:quiver/collection.dart';
......@@ -19,8 +20,9 @@ abstract class ImageProvider {
class _UrlFetcher implements ImageProvider {
final String _url;
final double _scale;
_UrlFetcher(this._url);
_UrlFetcher(this._url, this._scale);
Future<ImageInfo> loadImage() async {
UrlResponse response = await fetchUrl(_url);
......@@ -28,11 +30,17 @@ class _UrlFetcher implements ImageProvider {
print("Failed (${response.statusCode}) to load image $_url");
return null;
}
return new ImageInfo(image: await decodeImageFromDataPipe(response.body));
return new ImageInfo(
image: await decodeImageFromDataPipe(response.body),
scale: _scale
);
}
bool operator ==(other) => other is _UrlFetcher && _url == other._url;
int get hashCode => _url.hashCode;
bool operator ==(other) {
return other is _UrlFetcher && _url == other._url && _scale == other._scale;
}
int get hashCode => hashValues(_url, _scale);
}
const int _kDefaultSize = 1000;
......@@ -52,8 +60,8 @@ class _ImageCache {
});
}
ImageResource load(String url) {
return loadProvider(new _UrlFetcher(url));
ImageResource load(String url, { double scale: 1.0 }) {
return loadProvider(new _UrlFetcher(url, scale));
}
}
......
......@@ -1531,7 +1531,7 @@ class RawImage extends LeafRenderObjectWidget {
/// aspect ratio.
final double height;
/// If non-null, specify the image's scale.
/// Specifies the image's scale.
///
/// Used when determining the best display size for the image.
final double scale;
......@@ -1700,6 +1700,7 @@ class NetworkImage extends StatelessComponent {
this.src,
this.width,
this.height,
this.scale : 1.0,
this.color,
this.fit,
this.alignment,
......@@ -1722,6 +1723,11 @@ class NetworkImage extends StatelessComponent {
/// aspect ratio.
final double height;
/// Specifies the image's scale.
///
/// Used when determining the best display size for the image.
final double scale;
/// If non-null, apply this color filter to the image before painting.
final Color color;
......@@ -1749,7 +1755,7 @@ class NetworkImage extends StatelessComponent {
Widget build(BuildContext context) {
return new RawImageResource(
image: imageCache.load(src),
image: imageCache.load(src, scale: scale),
width: width,
height: height,
color: color,
......
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