downloadFile static method
Implementation
static Future<Uint8List?> downloadFile({
required String url,
required String cacheKey,
required void Function(int progress) onProgress,
Duration timeout = const Duration(seconds: 60),
}) async {
if (_operations.containsKey(cacheKey)) {
await _operations[cacheKey]?.cancel();
}
final CancelableOperation<Uint8List> op = CancelableOperation<Uint8List>.fromFuture(
_performDownload(url: url, cacheKey: cacheKey, onProgress: onProgress, timeout: timeout),
onCancel: () => _operations.remove(cacheKey),
);
_operations[cacheKey] = op;
try {
final Uint8List data = await op.value;
_operations.remove(cacheKey);
return data;
} catch (e) {
_operations.remove(cacheKey);
rethrow;
}
}