mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Improve image loading
This commit is contained in:
@@ -78,7 +78,13 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
|
||||
while (data == null && !stop) {
|
||||
try {
|
||||
data = await load(chunkEvents);
|
||||
data = await load(chunkEvents, () {
|
||||
if (stop) {
|
||||
throw const _ImageLoadingStopException();
|
||||
}
|
||||
});
|
||||
} on _ImageLoadingStopException {
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
if (e.toString().contains("Invalid Status Code: 404")) {
|
||||
rethrow;
|
||||
@@ -100,7 +106,7 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
throw Exception("Image loading is stopped");
|
||||
throw const _ImageLoadingStopException();
|
||||
}
|
||||
|
||||
if (data!.isEmpty) {
|
||||
@@ -127,6 +133,8 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
} on _ImageLoadingStopException {
|
||||
rethrow;
|
||||
} catch (e, s) {
|
||||
scheduleMicrotask(() {
|
||||
PaintingBinding.instance.imageCache.evict(key);
|
||||
@@ -138,7 +146,10 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents);
|
||||
Future<Uint8List> load(
|
||||
StreamController<ImageChunkEvent> chunkEvents,
|
||||
void Function() checkStop,
|
||||
);
|
||||
|
||||
String get key;
|
||||
|
||||
@@ -159,3 +170,7 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
}
|
||||
|
||||
typedef FileDecoderCallback = Future<ui.Codec> Function(Uint8List);
|
||||
|
||||
class _ImageLoadingStopException implements Exception {
|
||||
const _ImageLoadingStopException();
|
||||
}
|
||||
|
Reference in New Issue
Block a user