share method
Downloads a file from the provided url
and opens SharePlus dialog with
it.
Implementation
Future<void> share(String url, String name, {String? checksum}) async {
// Provided file might already be cached.
Uint8List? data;
if (checksum != null && CacheWorker.instance.exists(checksum)) {
data = (await CacheWorker.instance.get(checksum: checksum)).bytes;
}
if (data == null) {
final Directory temp = await getTemporaryDirectory();
final String path = '${temp.path}/$name';
await (await dio).download(url, path);
await SharePlus.instance.share(ShareParams(files: [XFile(path)]));
File(path).delete();
} else {
await SharePlus.instance.share(
ShareParams(files: [XFile.fromData(data, name: name)]),
);
}
}