plus_plugins
plus_plugins copied to clipboard
[Bug]: shareUri throws an exception when the share dialog is dismissed
Platform
Android 12
Plugin
share_plus
Version
9.0.0
Flutter SDK
3.19.6
Steps to reproduce
- Use shareLink function
- Build flutter app for web target
- Run the web app on a mobile phone
- Trigger the shareLink function by using a button in the app
- Dismiss the share drawer by tapping outside of it
Code Sample
final shareLink = Uri.parse("www.github.com");
final box = context.findRenderObject() as RenderBox?;
// shareUri seems to work better than share, but does not allow to set a subject for mail
final shareResult = await Share.shareUri(
shareLink,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
Logs
Can't run flutter run --verbose on a deployed web app, I see the following error message:
Exception: Navigator.share() failed: The operation was aborted
Flutter Doctor
$ flutter doctor -v
[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.19045.4291], locale de-DE)
• Flutter version 3.19.6 on channel stable at C:\Users\kbublitz\Tools\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 54e66469a9 (3 weeks ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] VS Code (version 1.90.0-insider)
• VS Code at C:\Users\kbublitz\AppData\Local\Programs\Microsoft VS Code Insiders
• Flutter extension version 3.89.20240501
[√] Connected device (2 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.119
• Edge (web) • edge • web-javascript • Microsoft Edge 124.0.2478.67
[√] Network resources
• All expected network resources are available.
• No issues found!
Checklist before submitting a bug
- [X] I searched issues in this repository and couldn't find such bug/problem
- [X] I Google'd a solution and I couldn't find it
- [X] I searched on StackOverflow for a solution and I couldn't find it
- [X] I read the README.md file of the plugin
- [X] I'm using the latest version of the plugin
- [X] All dependencies are up to date with
flutter pub upgrade - [X] I did a
flutter clean - [X] I tried running the example project
My guess is that the following lines from share() should also be added to the shareUri method in the share_plus_web.dart:
if (e.name case 'AbortError') { return _resultDismissed; }
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
Commenting to prevent auto closing. Would be nice to get any feedback if this issue will be fixed.
Is this an android error or a web error? your report says Android 12, but the logs talk about deploying for web
Yes it's the web target, but the error is still specific to Android, so I can't debug or test it in a web browser on PC. I wasn't sure what the template was asking for, the App is running in a web browser on an Android device when the exception appears.
Are you wrapping the call with a try/catch? The method throws exceptions if it fails: https://github.com/fluttercommunity/plus_plugins/blob/e61b4725332adfca756cd77c97354f2f29be0907/packages/share_plus/share_plus/lib/src/share_plus_web.dart#L32-L68
Sure we catch the exception and show an error popup (something generic like "Failed to share the URI"). It's just that I don't think there should be an exception in case of aborting the dialog, just to be consistent with the behavior in share() method.
My guess is that the difference between share() and shareUri is that the former has the following code in the try/catch:
if (e.name case 'AbortError') {
return _resultDismissed;
}
Which the shareUri doesn't have.
This should be an easy fix.