Handle error during systemShare

This commit is contained in:
Neeraj Gupta 2022-12-06 17:45:23 +05:30
parent ca1eab1f89
commit fe48140b08
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1

View file

@ -26,23 +26,35 @@ Future<void> share(
}) async { }) async {
final dialog = createProgressDialog(context, "Preparing..."); final dialog = createProgressDialog(context, "Preparing...");
await dialog.show(); await dialog.show();
final List<Future<String>> pathFutures = []; try {
for (File file in files) { final List<Future<String>> pathFutures = [];
// Note: We are requesting the origin file for performance reasons on iOS. for (File file in files) {
// This will eat up storage, which will be reset only when the app restarts. // Note: We are requesting the origin file for performance reasons on iOS.
// We could have cleared the cache had there been a callback to the share API. // This will eat up storage, which will be reset only when the app restarts.
pathFutures.add(getFile(file, isOrigin: true).then((file) => file.path)); // We could have cleared the cache had there been a callback to the share API.
if (file.fileType == FileType.livePhoto) { pathFutures.add(
pathFutures.add(getFile(file, liveVideo: true).then((file) => file.path)); getFile(file, isOrigin: true).then((fetchedFile) => fetchedFile.path),
);
if (file.fileType == FileType.livePhoto) {
pathFutures.add(
getFile(file, liveVideo: true)
.then((fetchedFile) => fetchedFile.path),
);
}
} }
final paths = await Future.wait(pathFutures);
await dialog.hide();
return Share.shareFiles(
paths,
// required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383
sharePositionOrigin: shareButtonRect(context, shareButtonKey),
);
} catch (e, s) {
_logger.severe(
"failed to fetch files for system share ${files.length}", e, s);
await dialog.hide();
await showGenericErrorDialog(context);
} }
final paths = await Future.wait(pathFutures);
await dialog.hide();
return Share.shareFiles(
paths,
// required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383
sharePositionOrigin: shareButtonRect(context, shareButtonKey),
);
} }
Rect shareButtonRect(BuildContext context, GlobalKey shareButtonKey) { Rect shareButtonRect(BuildContext context, GlobalKey shareButtonKey) {