download method

Future<void> download(
  1. PostItem item, {
  2. String? to,
})

Downloads the provided PostItem.

Implementation

Future<void> download(PostItem item, {String? to}) async {
  Log.debug('download($item)', '$runtimeType');

  try {
    try {
      await CacheWorker.instance
          .download(
            item.attachment.original.url,
            item.attachment.original.name,
            item.attachment.original.size,
            checksum: item.attachment.original.checksum,
            to: to,
          )
          .future;
    } catch (_) {
      // TODO: Implement.
      // if (item.onError != null) {
      //   await item.onError?.call();
      //   return SchedulerBinding.instance.addPostFrameCallback((_) {
      //     item = widget.children[_page];
      //     _download(item, to: to);
      //   });
      // } else {
      rethrow;
      // }
    }

    MessagePopup.success(
      item.attachment is ImageAttachment
          ? 'label_image_downloaded'.l10n
          : 'label_video_downloaded'.l10n,
    );
  } catch (_) {
    MessagePopup.error('${'err_could_not_download'.l10n}\n\n$e');
    rethrow;
  }
}