2021-04-10 06:28:12 +02:00
|
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
|
|
|
// ignore: implementation_imports
|
|
|
|
import 'package:flutter_cache_manager/src/cache_store.dart';
|
|
|
|
|
|
|
|
class CancelableGetFile {
|
|
|
|
CancelableGetFile(this.store);
|
|
|
|
|
|
|
|
Future<FileInfo> getFileUntil(String key,
|
|
|
|
{bool ignoreMemCache = false}) async {
|
2021-07-23 22:05:57 +02:00
|
|
|
FileInfo? product;
|
2021-04-10 06:28:12 +02:00
|
|
|
while (product == null && _shouldRun) {
|
|
|
|
product = await store.getFile(key, ignoreMemCache: ignoreMemCache);
|
|
|
|
await Future.delayed(Duration(milliseconds: 500));
|
|
|
|
}
|
2021-07-23 22:05:57 +02:00
|
|
|
if (product == null) {
|
|
|
|
return Future.error("Interrupted");
|
|
|
|
} else {
|
|
|
|
return product;
|
|
|
|
}
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cancel() {
|
|
|
|
_shouldRun = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get isGood => _shouldRun;
|
|
|
|
|
|
|
|
final CacheStore store;
|
|
|
|
|
|
|
|
bool _shouldRun = true;
|
|
|
|
}
|