Introducing share_plus Flutter Plugin: Share Content from Your App

Published on by Flutter News Hub

Introducing share_plus Flutter Plugin: Share Content from Your App

A Flutter plugin to share content from your Flutter app via the platform's share dialog. Wraps the ACTION_SEND Intent on Android and UIActivityViewController on iOS.

Usage

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

Share content with an optional subject:

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

For more control and feedback, use shareWithResult:

final result = await Share.shareWithResult('check out my website https://example.com');
if (result.status == ShareResultStatus.success) {
  print('Thank you for sharing my website!');
}

Share files with shareXFiles:

final result = await Share.shareXFiles([XFile('$/image.jpg')], text: 'Great picture');
if (result.status == ShareResultStatus.success) {
  print('Thank you for sharing the picture!');
}

On web, use SharePlus.shareXFiles() for file sharing. This utilizes the Web Share API or falls back to file download.

Known Issues

Sharing Data Created with XFile.fromData

When sharing data created with XFile.fromData, the plugin writes a temporal file inside the app's cache directory for sharing. Clean up this data periodically.

Mobile Platforms (Android and iOS)

Facebook Limitations

Facebook restrictions may affect sharing to WhatsApp, Instagram, and Facebook Messenger. Use native Facebook Sharing SDK for reliable sharing.

iPad Support

share_plus requires providing sharePositionOrigin on iPads to avoid issues or crashes. See a code example for implementation.

Learn More

Flutter News Hub