downloadFile method
- ChatItem item,
- FileAttachment attachment
Downloads the provided FileAttachment, if not downloaded already, or otherwise opens it or cancels the download.
Implementation
Future<void> downloadFile(ChatItem item, FileAttachment attachment) async {
if (attachment.isDownloading) {
attachment.cancelDownload();
} else if (await attachment.open() == false) {
try {
await attachment.download();
} catch (e) {
if (e is DioException && e.type == DioExceptionType.cancel) {
return;
}
await chat?.updateAttachments(item);
await Future.delayed(Duration.zero);
await attachment.download();
}
}
}