I am using Flutter's share
plugin to share contents from my app.
Share.share("A sample text that is shared")
Upon inspection, I found that the plugin invokes a method 'share'
on the MethodChannel
'plugins.flutter.io/share'
. This brings up a bottom sheet depending on the platform. What I would like to do is capture the closing of this share sheet. The share sheet can be closed by:
- Clicking on the region outside the sheet
- Pressing the back button on Android
- Clicking one of the options in the sheet which then opens up the respective application
Ideally, the Future
of this "share" would return the information which could be used to decide if the user aborted the share (cases 1 and 2) or proceeded along with the share(case 3). I am trying to do this to track the number of times a content is shared from my app.
The Share.share
returns a Future<void>
which I believe is resolved after the method is invoked on the platform channel.
Is there a way I can capture when the platform's share sheet closes just like we can capture when other widgets like dialogs are popped? Or more specifically,
Is there a way to know if the user actually proceeded with the share or not?
Something like this would have made it much easier:
Share.share("A sample text that is shared").then((bool isAborted) {
// Do something...
});
You have correctly figured out that this is not possible using the
share
plugin.Additionally, this is also not possible on the platform level anyway (see an Android answer for reference).
Moreover, the answer to your request would be to create an issue at flutter/flutter because this is a plugin by the Flutter team and GitHub issues are used to track such feature requests. In this case, you want to make sure to include
[share]
in your issue title. See the flutter/plugins README for reference.