[Bug]: Share_plus Web Must be handling a user gesture to perform a share request
Platform
chrome
Plugin
share_plus
Version
11.0.0
Flutter SDK
3.32.2
Steps to reproduce
I'm trying to share a link locally in Flutter web (Chrome) by adding a BLoC event that calls the share service. It works on Android and iOS, but on the web, I encounter the following exception:
[log] Failed to share URI [log] NotAllowedError: Failed to execute 'share' on 'Navigator': Must be handling a user gesture to perform a share request. [log] Navigator.share() failed: Failed to execute 'share' on 'Navigator': Must be handling a user gesture to perform a share request.
How can I resolve this exception?
Code Sample
Logs
[log] Failed to share uri
[log] NotAllowedError: Failed to execute 'share' on 'Navigator': Must be handling a user gesture to perform a share request.
[log] Navigator.share() failed: Failed to execute 'share' on 'Navigator': Must be handling a user gesture to perform a share request.
Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.2, on macOS 14.4.1 23E224 darwin-arm64, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.97.2)
[✓] Connected device (3 available)
[✓] Network resources
• 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
Hi, it seems that your issue is caused by calling the share functionality in the wrong context. Web works a bit differently compared to iOS and Android. MDN specifies that the share function can only be used when triggered by a user action. You can check this issue.
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