Commit d97df402 authored by Adam Barth's avatar Adam Barth

ImageCache should handle images that fail to decode (#4118)

parent f012a0fd
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'dart:ui' show hashValues; import 'dart:ui' show hashValues, Image;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/http.dart' as http; import 'package:flutter/http.dart' as http;
import 'package:mojo/core.dart' as mojo;
import 'image_decoder.dart'; import 'image_decoder.dart';
import 'image_resource.dart'; import 'image_resource.dart';
...@@ -53,10 +54,14 @@ class _UrlFetcher implements ImageProvider { ...@@ -53,10 +54,14 @@ class _UrlFetcher implements ImageProvider {
@override @override
Future<ImageInfo> loadImage() async { Future<ImageInfo> loadImage() async {
try { try {
return new ImageInfo( final Uri resolvedUrl = Uri.base.resolve(_url);
image: await decodeImageFromDataPipe(await http.readDataPipe(Uri.base.resolve(_url))), final mojo.MojoDataPipeConsumer dataPipe = await http.readDataPipe(resolvedUrl);
scale: _scale if (dataPipe == null)
); throw 'Unable to read data from: $resolvedUrl';
final Image image = await decodeImageFromDataPipe(dataPipe);
if (image == null)
throw 'Unable to decode image data from: $resolvedUrl';
return new ImageInfo(image: image, scale: _scale);
} catch (exception, stack) { } catch (exception, stack) {
FlutterError.reportError(new FlutterErrorDetails( FlutterError.reportError(new FlutterErrorDetails(
exception: exception, exception: exception,
......
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