Fix download stream not canceled

This commit is contained in:
Ming Ming 2021-09-29 02:43:50 +08:00
parent cf3f855cd3
commit aa1c90282c

View file

@ -57,12 +57,17 @@ class FileDownloader extends itf.FileDownloader {
} }
} }
DownloadEvent.listenDownloadComplete() StreamSubscription<DownloadCompleteEvent>? subscription;
try {
subscription = DownloadEvent.listenDownloadComplete()
..onData(onDownloadComplete) ..onData(onDownloadComplete)
..onError((e, stackTrace) { ..onError((e, stackTrace) {
completer.completeError(e, stackTrace); completer.completeError(e, stackTrace);
}); });
await completer.future; await completer.future;
} finally {
subscription?.cancel();
}
return uri; return uri;
} on PlatformException catch (e) { } on PlatformException catch (e) {
switch (e.code) { switch (e.code) {