saveToGallery method

Future<void> saveToGallery(
  1. String url,
  2. String name, {
  3. String? checksum,
  4. int? size,
  5. bool isImage = false,
})

Downloads a video or an image from the provided url and saves it to the gallery.

Implementation

Future<void> saveToGallery(
  String url,
  String name, {
  String? checksum,
  int? size,
  bool isImage = false,
}) async {
  if (isImage) {
    // SVGs can not be saved to the gallery.
    if (name.endsWith('.svg')) {
      throw UnsupportedError('SVGs are not supported in gallery.');
    }

    final CacheEntry cache = await CacheWorker.instance.get(
      url: url,
      checksum: checksum,
    );

    await ImageGallerySaver.saveImage(cache.bytes!, name: name);
  } else {
    final File? file = await PlatformUtils.download(
      url,
      name,
      size,
      checksum: checksum,
      temporary: true,
    );

    await ImageGallerySaver.saveFile(file!.path, name: name);
  }
}