Skip to content

Commit 5847a6a

Browse files
committed
## 3.4.1
* clearMemoryCacheWhenDispose is not working with imageCacheName property, obtainCacheStatus method should be overrided.(#44)
1 parent 088f5c3 commit 5847a6a

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.4.1
2+
3+
* clearMemoryCacheWhenDispose is not working with imageCacheName property, obtainCacheStatus method should be overrided.(#44)
4+
15
## 3.4.0
26

37
* Migrate to 3.3.0 (load=>loadBuffer)

lib/src/extended_image_provider.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'dart:async';
2+
// ignore: unnecessary_import
13
import 'dart:typed_data';
24
import 'dart:ui' as ui show Codec, ImmutableBuffer;
35
import 'package:extended_image_library/src/extended_resize_image_provider.dart';
6+
import 'package:flutter/foundation.dart';
47
import 'package:flutter/painting.dart' hide imageCache;
58

69
/// The cached raw image data
@@ -123,4 +126,102 @@ mixin ExtendedImageProvider<T extends Object> on ImageProvider<T> {
123126
final T key = await obtainKey(configuration);
124127
return cache.evict(key, includeLive: includeLive);
125128
}
129+
130+
@override
131+
Future<ImageCacheStatus?> obtainCacheStatus({
132+
required ImageConfiguration configuration,
133+
ImageErrorListener? handleError,
134+
}) {
135+
return _obtainCacheStatus(
136+
configuration: configuration,
137+
handleError: handleError,
138+
);
139+
}
140+
141+
// copy from offical
142+
Future<ImageCacheStatus?> _obtainCacheStatus({
143+
required ImageConfiguration configuration,
144+
ImageErrorListener? handleError,
145+
}) {
146+
// ignore: unnecessary_null_comparison
147+
assert(configuration != null);
148+
final Completer<ImageCacheStatus?> completer =
149+
Completer<ImageCacheStatus?>();
150+
_createErrorHandlerAndKey(
151+
configuration,
152+
(T key, ImageErrorListener innerHandleError) {
153+
completer.complete(imageCache.statusForKey(key));
154+
},
155+
(T? key, Object exception, StackTrace? stack) async {
156+
if (handleError != null) {
157+
handleError(exception, stack);
158+
} else {
159+
InformationCollector? collector;
160+
assert(() {
161+
collector = () => <DiagnosticsNode>[
162+
DiagnosticsProperty<ImageProvider>('Image provider', this),
163+
DiagnosticsProperty<ImageConfiguration>(
164+
'Image configuration', configuration),
165+
DiagnosticsProperty<T>('Image key', key, defaultValue: null),
166+
];
167+
return true;
168+
}());
169+
FlutterError.reportError(FlutterErrorDetails(
170+
context: ErrorDescription(
171+
'while checking the cache location of an image'),
172+
informationCollector: collector,
173+
exception: exception,
174+
stack: stack,
175+
));
176+
completer.complete(null);
177+
}
178+
},
179+
);
180+
return completer.future;
181+
}
182+
183+
/// This method is used by both [resolve] and [obtainCacheStatus] to ensure
184+
/// that errors thrown during key creation are handled whether synchronous or
185+
/// asynchronous.
186+
void _createErrorHandlerAndKey(
187+
ImageConfiguration configuration,
188+
_KeyAndErrorHandlerCallback<T> successCallback,
189+
_AsyncKeyErrorHandler<T?> errorCallback,
190+
) {
191+
T? obtainedKey;
192+
bool didError = false;
193+
Future<void> handleError(Object exception, StackTrace? stack) async {
194+
if (didError) {
195+
return;
196+
}
197+
if (!didError) {
198+
errorCallback(obtainedKey, exception, stack);
199+
}
200+
didError = true;
201+
}
202+
203+
Future<T> key;
204+
try {
205+
key = obtainKey(configuration);
206+
} catch (error, stackTrace) {
207+
handleError(error, stackTrace);
208+
return;
209+
}
210+
key.then<void>((T key) {
211+
obtainedKey = key;
212+
try {
213+
successCallback(key, handleError);
214+
} catch (error, stackTrace) {
215+
handleError(error, stackTrace);
216+
}
217+
}).catchError(handleError);
218+
}
126219
}
220+
221+
/// Signature for the callback taken by [_createErrorHandlerAndKey].
222+
typedef _KeyAndErrorHandlerCallback<T> = void Function(
223+
T key, ImageErrorListener handleError);
224+
225+
/// Signature used for error handling by [_createErrorHandlerAndKey].
226+
typedef _AsyncKeyErrorHandler<T> = Future<void> Function(
227+
T key, Object exception, StackTrace? stack);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: extended_image_library
22
description: package library for extended_image, extended_text and extended_text_field, provide common base class.
3-
version: 3.4.0
3+
version: 3.4.1
44
homepage: https://github.com/fluttercandies/extended_image_library
55

66
environment:

0 commit comments

Comments
 (0)