Skip to main content

Using Share Plus

To use this plugin, add share_plus as a dependency in your pubspec.yaml file.


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');

The share method also takes an optional subject that will be used when sharing to email.

Share.share('check out my website', subject: 'Look what I made!');

To share one or multiple files invoke the static shareFiles method anywhere in your Dart code. Optionally you can also pass in text and subject.

Share.shareFiles(['${directory.path}/image.jpg'], text: 'Great picture');
Share.shareFiles(['${directory.path}/image1.jpg', '${directory.path}/image2.jpg']);

If you are interested in the action your user performed with the share sheet, you can instead use the shareWithResult and shareFilesWithResult methods.

final result = await Share.shareWithResult('check out my website');

if (result.status == ShareResultStatus.success) {
print('thank you for sharing my website!');
final result = await Share.shareFilesWithResult(['${directory.path}/image.jpg'], text: 'Great picture');

if (result.status == ShareResultStatus.dismissed) {
print('did you not like the picture?');