@@ -120,55 +120,65 @@ class ImageLoader implements platform.ImageLoader {
120
120
) {
121
121
var streamController = StreamController <ui.Codec >();
122
122
123
- final stream = cacheManager.getFileStream (
124
- url,
125
- withProgress: true ,
126
- headers: headers,
127
- key: cacheKey,
128
- );
123
+ try {
124
+ final stream = cacheManager.getFileStream (
125
+ url,
126
+ withProgress: true ,
127
+ headers: headers,
128
+ key: cacheKey,
129
+ );
129
130
130
- var state = _State .open;
131
+ var state = _State .open;
131
132
132
- stream.listen (
133
- (event) {
134
- if (event is DownloadProgress ) {
135
- chunkEvents.add (
136
- ImageChunkEvent (
137
- cumulativeBytesLoaded: event.downloaded,
138
- expectedTotalBytes: event.totalSize,
139
- ),
140
- );
141
- }
142
- if (event is FileInfo ) {
143
- if (state == _State .open) {
144
- state = _State .waitingForData;
133
+ stream.listen (
134
+ (event) {
135
+ if (event is DownloadProgress ) {
136
+ chunkEvents.add (
137
+ ImageChunkEvent (
138
+ cumulativeBytesLoaded: event.downloaded,
139
+ expectedTotalBytes: event.totalSize,
140
+ ),
141
+ );
145
142
}
146
-
147
- event.file.readAsBytes ().then ((value) => decode (value)).then ((data) {
148
- streamController.add (data);
149
- if (state == _State .closing) {
150
- streamController.close ();
151
- chunkEvents.close ();
143
+ if (event is FileInfo ) {
144
+ if (state == _State .open) {
145
+ state = _State .waitingForData;
152
146
}
147
+
148
+ event.file
149
+ .readAsBytes ()
150
+ .then ((value) => decode (value))
151
+ .then ((data) {
152
+ streamController.add (data);
153
+ if (state == _State .closing) {
154
+ streamController.close ();
155
+ chunkEvents.close ();
156
+ }
157
+ });
158
+ }
159
+ },
160
+ onError: (e, st) {
161
+ scheduleMicrotask (() {
162
+ evictImage ();
153
163
});
154
- }
155
- },
156
- onError : (e, st) {
157
- scheduleMicrotask (( ) {
158
- evictImage ();
159
- } );
160
- streamController. addError (e, st);
161
- },
162
- onDone : () async {
163
- if (state == _State .open) {
164
- streamController. close ();
165
- chunkEvents. close ( );
166
- } else if (state == _State .waitingForData ) {
167
- state = _State .closing;
168
- }
169
- },
170
- cancelOnError : true ,
171
- );
164
+ streamController. addError (e, st);
165
+ },
166
+ onDone : () async {
167
+ if (state == _State .open ) {
168
+ streamController. close ();
169
+ chunkEvents. close ( );
170
+ } else if (state == _State .waitingForData) {
171
+ state = _State .closing;
172
+ }
173
+ },
174
+ cancelOnError : true ,
175
+ );
176
+ } on Object catch (e, st ) {
177
+ scheduleMicrotask (() {
178
+ evictImage ();
179
+ });
180
+ streamController. addError (e, st);
181
+ }
172
182
173
183
return streamController.stream;
174
184
}
0 commit comments