E.K.
E.K.

Reputation: 65

Flutter package share_plus : unexpected async-await behaviour

This is a Flutter plugin to share content from your Flutter app via the platform's share dialog. Reference: https://pub.dev/packages/share_plus/install

I am using the following commands to share a picture with a caption or a text message only.

await Share.shareFiles([imagePath],text: text); //share picture + text

or

await Share.share(text,); //share text only

Here .share is a Future Function and I would like to await until have it done. This seems not happening. You can quickly test it by adding a print command after one of the above command as following.

await Share.share(text,); print('this should be printed after the sharing process');

You will notice the text is printed in the console before the sharing has completed (the platform's share dialog is still on).

Am I missing something? Or you believe there is an issue within the package?

Many thanks in advance

Upvotes: 4

Views: 2025

Answers (2)

priyank apps
priyank apps

Reputation: 121

use share package instead to share files

Upvotes: 0

Colin
Colin

Reputation: 360

The plugin has another function that returns a result when the sharing is complete.

await Share.shareWithResult(text);
print('this is printed after the sharing process');

Upvotes: 0

Related Questions