Using Share Plus
To use this plugin, add share_plus
as a dependency in your pubspec.yaml file.
Example
Import the library.
import 'package:share_plus/share_plus.dart';
Then invoke the static share
method anywhere in your Dart code.
Share.share('check out my website https://example.com');
The share
method also takes an optional subject
that will be used when
sharing to email.
Share.share('check out my website https://example.com', subject: 'Look what I made!');
If you are interested in the action your user performed with the share sheet, you can instead use the shareWithResult
method.
final result = await Share.shareWithResult('check out my website https://example.com');
if (result.status == ShareResultStatus.success) {
print('Thank you for sharing my website!');
}
To share one or multiple files, invoke the static shareXFiles
method anywhere in your Dart code. The method returns a ShareResult
. Optionally, you can pass subject
, text
and sharePositionOrigin
.
final result = await Share.shareXFiles(['XFile(${directory.path}/image.jpg')], text: 'Great picture');
if (result.status == ShareResultStatus.success) {
print('Thank you for sharing the picture!');
}
final result = await Share.shareXFiles(['XFile(${directory.path}/image1.jpg'), XFile('${directory.path}/image2.jpg')]);
if (result.status == ShareResultStatus.dismissed) {
print('Did you not like the pictures?');
}