saveToGallery method
- PostItem item
Downloads the provided PostItem and saves it to the gallery.
Implementation
Future<void> saveToGallery(PostItem item) async {
Log.debug('saveToGallery($item)', '$runtimeType');
// Tries downloading the [item].
Future<void> download() async {
await PlatformUtils.saveToGallery(
item.attachment.original.url,
item.attachment.original.name,
checksum: item.attachment.original.checksum,
size: item.attachment.original.size,
isImage: item.attachment is ImageAttachment,
);
MessagePopup.success(
item.attachment is ImageAttachment
? 'label_image_saved_to_gallery'.l10n
: 'label_video_saved_to_gallery'.l10n,
);
}
try {
try {
await download();
} on DioException catch (_) {
// TODO: Implement.
// if (item.onError != null && e.response?.statusCode == 403) {
// await item.onError?.call();
// await Future.delayed(Duration.zero);
// await download();
// } else {
rethrow;
// }
}
} on UnsupportedError catch (_) {
MessagePopup.error('err_unsupported_format'.l10n);
} catch (_) {
MessagePopup.error('err_could_not_download'.l10n);
rethrow;
}
}