share_plus

v11.1.0

Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS.

Package archive: https://pubdev.letsnova.ru/api/archives/share_plus/11.1.0.tar.gz

Installdart pub add share_plus

Readme

share_plus

share_plus pub points pub package

A Flutter plugin to share content from your Flutter app via the platform's share dialog.

Wraps the ACTION_SEND Intent on Android, UIActivityViewController on iOS, or equivalent platform content sharing methods.

Platform Support

Shared content Android iOS MacOS Web Linux Windows
Text
URI As text As text As text
Files

Also compatible with Windows and Linux by using "mailto" to share text via Email.

Sharing files is not supported on Linux.

Requirements

  • Flutter >=3.22.0
  • Dart >=3.4.0 <4.0.0
  • iOS >=12.0
  • MacOS >=10.14
  • Android compileSDK 34
  • Java 17
  • Android Gradle Plugin >=8.3.0
  • Gradle wrapper >=8.4

Usage

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

Share Text

Access the SharePlus instance via SharePlus.instance. Then, invoke the share() method anywhere in your Dart code.

import 'package:share_plus/share_plus.dart';
                
                SharePlus.instance.share(
                  ShareParams(text: 'check out my website https://example.com')
                );
                

The share() method requires the ShareParams object, which contains the content to share.

These are some of the accepted parameters of the ShareParams class:

  • text: text to share.
  • title: content or share-sheet title (if supported).
  • subject: email subject (if supported).

Check the class documentation for more details.

share() returns status object that allows to check the result of user action in the share sheet.

final result = await SharePlus.instance.share(params);
                
                if (result.status == ShareResultStatus.success) {
                    print('Thank you for sharing my website!');
                }
                

Share Files

To share one or multiple files, provide the files list in ShareParams. Optionally, you can pass title, text and sharePositionOrigin.

import 'package:share_plus/share_plus.dart';
                import 'package:cross_file/cross_file.dart';
                
                final params = ShareParams(
                  text: 'Great picture',
                  files: [XFile('${directory.path}/image.jpg')], 
                );
                
                final result = await SharePlus.instance.share(params);
                
                if (result.status == ShareResultStatus.success) {
                    print('Thank you for sharing the picture!');
                }
                
import 'package:share_plus/share_plus.dart';
                import 'package:cross_file/cross_file.dart';
                
                final params = ShareParams(
                  files: [
                    XFile('${directory.path}/image1.jpg'), 
                    XFile('${directory.path}/image2.jpg'),
                  ],
                );
                
                final result = await SharePlus.instance.share(params);
                
                if (result.status == ShareResultStatus.dismissed) {
                    print('Did you not like the pictures?');
                }
                

On web, this uses the Web Share API if it's available. Otherwise it falls back to downloading the shared files. See Can I Use - Web Share API to understand which browsers are supported. This builds on the cross_file package.

File downloading fallback mechanism for web can be disabled by setting:

import 'package:share_plus/share_plus.dart';
                
                ShareParams(
                  // rest of params
                  downloadFallbackEnabled: false,
                )
                

Share Data

You can also share files that you dynamically generate from its data using XFile.fromData.

To set the name of such files, use the fileNameOverrides parameter, otherwise the file name will be a random UUID string.

import 'package:share_plus/share_plus.dart';
                import 'package:cross_file/cross_file.dart';
                import 'dart:convert';
                
                final params = ShareParams(
                  files: [XFile.fromData(utf8.encode(text), mimeType: 'text/plain')], 
                  fileNameOverrides: ['myfile.txt']
                );
                
                SharePlus.instance.share(params);
                

[!CAUTION] The name parameter in the XFile.fromData method is ignored in most platforms. Use fileNameOverrides instead.

Share URI

iOS supports fetching metadata from a URI when shared using UIActivityViewController. This special functionality is only properly supported on iOS. On other platforms, the URI will be shared as plain text.

import 'package:share_plus/share_plus.dart';
                
                final params = ShareParams(uri: uri);
                
                SharePlus.instance.share(params);
                

Share Results

All three methods return a ShareResult object which contains the following information:

  • status: a ShareResultStatus
  • raw: a String describing the share result, e.g. the opening app ID.

Note: status will be ShareResultStatus.unavailable if the platform does not support identifying the user action.

Other Parameters

Title

Used as share sheet title where supported.

  • Provided to Android's Intent.createChooser as the title, as well as, EXTRA_TITLE Intent extra.
  • Provided to web Navigator Share API as title.
ShareParams(
                  // rest of params
                  title: 'Title',
                )
                

Subject

Used as email subject where supported (e.g. EXTRA_SUBJECT on Android)

When using the email fallback, this will be the subject of the email.

ShareParams(
                  // rest of params
                  subject: 'Subject',
                )
                

Excluded Cupertino Activities

On iOS or macOS, if you want to exclude certain options from appearing in your share sheet, you can set the excludedCupertinoActivities array.

For the list of supported excludedCupertinoActivities, refer to CupertinoActivityType.

ShareParams(
                  // rest of params
                  excludedCupertinoActivities: [CupertinoActivityType.postToFacebook],
                )
                

Known Issues

Sharing data created with XFile.fromData

When sharing data created with XFile.fromData, the plugin will write a temporal file inside the cache directory of the app, so it can be shared.

Although the OS should take care of deleting those files, it is advised, that you clean up this data once in a while (e.g. on app start).

You can access this directory using path_provider getTemporaryDirectory.

Alternatively, don't use XFile.fromData and instead write the data down to a File with a path before sharing it, so you control when to delete it.

Mobile platforms (Android and iOS)

Sharing images + text

When attempting to share images with text, some apps may fail to properly accept the share action with them.

For example, due to restrictions set up by Meta/Facebook this plugin isn't capable of sharing data reliably to Facebook related apps on Android and iOS. This includes eg. sharing text to the Facebook Messenger.

If you require this functionality please check the native Facebook Sharing SDK (https://developers.facebook.com/docs/sharing) or search for other Flutter plugins implementing this SDK. More information can be found in this issue.

Other apps may also give problems when attempting to share content to them. This is because 3rd party app developers do not properly implement the logic to receive share actions.

We cannot guarantee that a 3rd party app will properly implement the share functionality. Therefore, all bugs reported regarding compatibility with a specific app will be closed.

Localization in Apple platforms

It could happen that the Share sheet appears with a different language, as reported here.

To fix this issue, you will have to setup the keys CFBundleAllowMixedLocalizations and CFBundleDevelopmentRegion in your project's info.plist.

For more information check the CoreFoundationKeys documentation.

iPad

share_plus requires iPad users to provide the sharePositionOrigin parameter.

Without it, share_plus will not work on iPads and may cause a crash or leave the UI unresponsive.

To avoid that problem, provide the sharePositionOrigin.

For example:

// Use Builder to get the widget context
                Builder(
                  builder: (BuildContext context) {
                    return ElevatedButton(
                      onPressed: () => _onShare(context),
                          child: const Text('Share'),
                     );
                  },
                ),
                
                // _onShare method:
                final box = context.findRenderObject() as RenderBox?;
                
                await SharePlus.instance.share(
                  ShareParams(
                    text: text,
                    sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
                  )
                );
                

See the main.dart in the example for a complete example.

Migrating from Share.share() to SharePlus.instance.share()

The static methods Share.share(), Share.shareUri() and Share.shareXFiles() have been deprecated in favor of the SharePlus.instance.share(params).

To convert code using Share.share() to the new SharePlus class:

  1. Wrap the current parameters in a ShareParams object.
  2. Change the call to SharePlus.instance.share().

e.g.

import 'package:share/share.dart';
                
                Share.share("Shared text");
                
                Share.shareUri("http://example.com");
                
                Share.shareXFiles(files);
                

Becomes:

import 'package:share_plus/share_plus.dart';
                
                SharePlus.instance.share(
                  ShareParams(text: "Shared text"),
                );
                
                SharePlus.instance.share(
                  ShareParams(uri: "http://example.com"),
                );
                
                SharePlus.instance.share(
                  ShareParams(files: files),
                );
                

Learn more

Changelog

11.1.0

  • FEAT(share_plus): Added excludedCupertinoActivities share parameter (#3376). (f9fdadb4)
  • DOCS(all): improve documentation across multiple README files (#3630). (643e12df)
  • DOCS(share-plus): Update README.md. (2aa9f7e0)

11.0.0

Note: This release has breaking changes.

  • BREAKING FEAT(share_plus): SharePlus refactor (#3404). (0a19d460)

This version introduces the new SharePlus class with the share(params) method. It replaces the old Share class, which has been deprecated but can still be used. Check the section "Migrating from Share to SharePlus" in the README.md.

10.1.4

  • FIX(share_plus): fallback for shareXFiles() to use download on web (#3388). (95a12ee3)

10.1.3

  • REFACTOR(all): Use range of flutter_lints for broader compatibility (#3371). (8a303add)
  • FIX(share_plus): A function declaration without a prototype is deprecated in all versions of C (#3375). (40f9c421)
  • FIX(share_plus): Set correct Flutter and Dart versions requirements (#3363). (65616668)

10.1.2

  • FIX(share_plus): Update privacy manifest path (#3349). (d884a991)

10.1.1

  • FIX(share_plus): #3322 Downscale previews on iOS to avoid issues with huge images (#3320). (d8c95c2c)

10.1.0

  • FEAT(share_plus): Add Swift Package Manager support (#3169). (b3970225)

10.0.3

  • FIX(share_plus): mime compatible with v2 (v1 still supported) (#3309). (401db75e)
  • FIX(all): Clean up macOS Privacy Manifests (#3268). (d7b98ebd)
  • FIX(all): Add macOS Privacy Manifests (#3251). (bf5dad2a)

10.0.2

  • FIX(share_plus): #2910 Handle user dismissing dialog on shareUri() in web (#3175). (bba78118)

10.0.1

  • CHORE(share_plus): Update to package:web to ^1.0.0 (#3105). (1f23910a)

10.0.0

Note: This release has breaking changes.

  • BREAKING FEAT(share_plus): Introduce optional parameter nameOverride to shareXFiles. (#3077). (f483bce7)
  • REFACTOR(all): Remove website files, configs, mentions (#3018). (ecc57146)
  • FIX(all): changed homepage url in pubspec.yaml (#3099). (66613656)
  • DOCS(share_plus): Update README.md (#2903). (2a547eb3)

9.0.0

Note: This release has breaking changes.

  • BREAKING REFACTOR(share_plus): Share API cleanup (#2832). (fd0511ca)

8.0.3

  • REFACTOR(share_plus): Migrate Android example to use the new plugins declaration (#2742). (a73af898)
  • FIX(share_plus): Recover ShareSuccessManager state after error (#2817). (2b12d8a8)
  • DOCS(share_plus): Add info regarding localization on Apple to README (#2764). (43f9a305)
  • DOCS(share_plus): remove typo from the changelog (#2747). (961c8e2d)

8.0.2

Note: This release has breaking changes.

In this release plugin migrated to package:web, meaning that it now supports WASM!

Plugin now requires the following:

  • Flutter >=3.19.0
  • Dart >=3.3.0
  • compileSDK 34 for Android part
  • Java 17 for Android part
  • Gradle 8.4 for Android part
  • BREAKING FEAT(share_plus): Migrate to package:web (#2709). (641e7905)
  • BREAKING BUILD(share_plus): Target Java 17 on Android (#2730). (e6853a06)
  • BREAKING BUILD(sensors_plus): Update to target and compile SDK 34 (#2712). (b752fc3)
  • FIX(share_plus): Resolve deprecation warning in Android part (#2717). (5913ac72)
  • FIX(share_plus): add sharePositionOrigin parameter to shareUri (#2517). (f896d94e)
  • FIX(share_plus): Add missing call to result for shareUri on iOS (#2616). (65f23a5d)
  • FIX(share_plus): Add iOS Privacy Info (#2586). (17fc2e05)
  • FIX(share_plus): Ensure subject is not null before calling putExtra(Intent.EXTRA_SUBJECT, subject) (#2518). (f0bbbefc)
  • FEAT(share_plus): Update min iOS target to 12 (#2662). (5cef2e50)
  • DOCS(share_plus): Fix supported platforms in README (#2510). (6b4b855b)

8.0.1

Note: DO NOT USE THIS RELEASE. It is invalid due to a publishing issue

8.0.0

Note: This release was retracted due to (#2251).

7.2.2

  • FIX(share_plus): Ensure subject is not null before calling putExtra(Intent.EXTRA_SUBJECT, subject) (#2518). (f0bbbefc)
  • DOCS(share_plus): Fix supported platforms in README (#2510). (6b4b855b)

7.2.1

  • CHORE(share_plus): Update share_plus_platform_interface for compatibility with uuid 4.x

7.2.0

Info: This release is a replacement for release 8.0.0, which was retracted due to issue (#2251). As breaking change was reverted the major release was also reverted in favor of this one.

  • FIX(share_plus): Change Kotlin version from 1.9.10 to 1.7.22 (#2252). (d4954f36)
  • FIX(share_plus): Revert bump to compileSDK 34 (#2234). (6af2328d)
  • FEAT(share_plus): Remove deprecated VALID_ARCHS iOS property (#2024). (bb79888e)
  • DOCS(share_plus): Fix usage code snippets (#2106). (346e07ea)

7.1.0

  • FIX(share_plus): Regenerate iOS and MacOS example apps (#1869). (5db20ba7)
  • FEAT(share_plus): Allow user to share URI with preview image on the iOS native share sheet (#1779). (c83b667e)
  • DOCS(share_plus): Updated document with latest available method (#1917). (7fbe3de6)
  • DOCS(all): Fix example links on pub.dev (#1863). (d726035a)

7.0.2

  • CHORE(share_plus): Update file dependency constraints (#1853). (d8ff0cdb)

7.0.1

7.0.0

Note: This release has breaking changes.

  • CHORE(share_plus_plus): Update Flutter dependencies, set Flutter >=3.3.0 and Dart to >=2.18.0 <4.0.0
  • BREAKING FIX(all): Add support of namespace property to support Android Gradle Plugin (AGP) 8 (#1727). Projects with AGP < 4.2 are not supported anymore. It is highly recommended to update at least to AGP 7.0 or newer.
  • BREAKING CHORE(share_plus): Bump min Android to 4.4 (API 19) and iOS to 11, update podspec file (#1773).
  • REFACTOR(share_plus): Remove manual dependency override in example app.

6.3.4

  • FIX(all): Revert addition of namespace to avoid build fails on old AGPs (#1725).

6.3.3

  • FIX(share_plus): Add compatibility with AGP 8 (Android Gradle Plugin) (#1706).
  • FIX(share_plus_android): Fix strict compilation errors in MIME reduction function (#1650).

6.3.2

  • FIX(share_plus): Set exported=false for BroadcastReceiver on Android (#1613).
  • FIX(package_info_plus): Make example app content scrollable (#1614).
  • FIX(all): Fix depreciations for flutter 3.7 and 2.19 dart (#1529).

6.3.1

  • FIX: Fix the error of requestCode value range. (#1340).
  • FIX: example broken on web (#1334).
  • DOCS: Updates for READMEs and website pages (#1389).

6.3.0

  • FIX: remove canLaunch check (#1315).
  • FEAT: Show destination for share with result in example, update example UI (#1314).

6.2.0

  • FIX: return correct share result on android (#1301).
  • FEAT: remove direct dependence of url_launcher (#1295).
  • DOCS: #1299 document XFile.fromData (#1300).

6.1.0

  • FIX: export XFile (#1286).
  • FEAT: share XFile created using File.fromData() (#1284).

6.0.1

  • FIX: Increase min Flutter version to fix dartPluginClass registration (#1275).

6.0.0

Note: This release has breaking changes.

  • FIX: lint warnings - add missing dependency for tests (#1233).
  • FIX: Show NSSharingServicePicker asynchronously on main thread (#1223).
  • BREAKING REFACTOR: two-package federated architecture (#1238).

5.0.0

Note: This release has breaking changes.

  • BREAKING FEAT: Native share UI for Windows (#1158).

4.5.3

  • CHORE: Version tagging using melos.

4.5.2

  • Update internal dependencies

4.5.1

  • Update internal dependencies

4.5.0

  • iOS: Remove usage of deprecated UIApplication.keyWindow in iOS 13+
  • Add shareXFiles implementations
  • Deprecate shareFiles* implementations
  • Enable shareXFiles implementations on Web

4.4.0

  • Reverted changes in 4.2.0 due to crash issues. See #1081

4.3.0

  • iOS: Throw PlatformException when iPad share dialog not appearing (sharePositionOrigin not in sourceView)

4.2.0

  • iOS: Fix Instagram does not show up in provider list for web links
    • issue #459 appear again
    • put back NSURL for the shareText, when text is pure URL
    • using LPMetadataProvider to get LPLinkMetadata make the user experience better

4.1.0

  • iOS: Fix text sharing.
    • Previously, the text was being encoded as a URL, this caused the share sheet to appear empty.
    • Now the shared text is not encoded as a URL anymore but rather shared as plain text.
    • Sharing text + subject + attachments should work on apps that support that (e.g. Mail app).
    • Example: Sharing Text + Image on Telegram is possible and both are shared.
    • Some apps still have limitations with sharing. For example, Gmail app does not support the subject field.
    • Related issue: #730

4.0.10+1

  • Add issue_tracker link.

4.0.10

  • iOS: Fix 'share text' not showing when share files

4.0.9

  • iOS: Fix image file names not preserved

4.0.8

  • iOS: Fix 'Save Image' option not showing

4.0.7

  • Add documentation iPad

4.0.6

  • iOS: Fix file names not preserved and poor previews for files

4.0.5

  • Update dependencies
  • Fix analyzer warnings

4.0.4

  • iOS: Fix subject not working when sharing raw url or files via email

4.0.3

  • Android: Revert increased minSdkVersion back to 16
  • Gracefully fall back from shareWithResult to regular share methods on unsupported platforms
  • Improve documentation for shareWithResult methods

4.0.2

  • Fix type mismatch on Android for some users
  • Set min Flutter to 1.20.0 for all platforms
  • Lower Android minSdkVersion to 22

4.0.1

  • Hotfix dependencies

4.0.0

  • iOS, Android, MacOS: Add shareWithResult methods to get feedback on user action
  • Android: Increased minSdkVersion to 23
  • MacOS: Native sharing implementation

3.1.0

  • Android: Migrate to Kotlin
  • Android: Update dependencies, build config updates

3.0.5

  • Fix example embedding issue

3.0.4

  • iOS: Fixed sharing malformed URLs

3.0.3

  • Improve documentation for shareFiles method

3.0.2

  • Apply code improvements
  • Update gradle for plugin
  • Update flutter dependencies

3.0.1

  • Update Android dependencies for plugin and example, bump compileSDK to 31

3.0.0

  • Remove deprecated method registerWith (of Android v1 embedding)

2.2.0

  • migrate integration_test to flutter sdk

2.1.5

  • Fixed: Use NSURL for web links (iOS)

2.1.4

  • Android: migrate to mavenCentral

2.1.3

  • Update iOS share target to present on the top ViewController. This fixes "Unable to present" errors when the app is already presenting such as in an add to app scenario.

2.1.2

  • Do not tear down method channel onDetachedFromActivity.

2.1.1

  • Updated iOS share sheet preview title to use subject when text is not set

2.1.0

  • Fixes #241 resolves issues with deprecations as of android API version 29 and replaces the requirement for external storage locations with an easy application cache usage.

2.0.3

  • Improve documentation

2.0.2

  • Fixed crash on launch when running iOS 12.x and below

2.0.1

  • Added preview title to iOS share sheet

2.0.0

  • Migrated to null safety
  • Add macOS support (share_plus_macos)

1.2.0

  • Add Web support (share_plus_web)
  • Rename method channel to avoid conflicts

1.1.1

  • Transfer to plus-plugins monorepo

0.7.0

  • Add Linux support for basic share capabilities.

0.6.6

  • Transfer package to Flutter Community under new name share_plus.

0.6.5

  • Added support for sharing files

0.6.4+5

  • Update package:e2e -> package:integration_test

0.6.4+4

  • Update package:e2e reference to use the local version in the flutter/plugins repository.

0.6.4+3

  • Post-v2 Android embedding cleanup.

0.6.4+2

  • Update lower bound of dart dependency to 2.1.0.

0.6.4+1

0.6.4

  • Remove Android dependencies fallback.
  • Require Flutter SDK 1.12.13+hotfix.5 or greater.
  • Fix CocoaPods podspec lint warnings.

0.6.3+8

  • Replace deprecated getFlutterEngine call on Android.

0.6.3+7

  • Updated gradle version of example.

0.6.3+6

  • Make the pedantic dev_dependency explicit.

0.6.3+5

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Require Flutter SDK 1.10.0 or greater.

0.6.3+4

  • Fix pedantic lints. This shouldn't affect existing functionality.

0.6.3+3

  • README update.

0.6.3+2

  • Remove AndroidX warnings.

0.6.3+1

  • Include lifecycle dependency as a compileOnly one on Android to resolve potential version conflicts with other transitive libraries.

0.6.3

  • Support the v2 Android embedder.
  • Update to AndroidX.
  • Migrate to using the new e2e test binding.
  • Add a e2e test.

0.6.2+4

  • Define clang module for iOS.

0.6.2+3

  • Fix iOS crash when setting subject to null.

0.6.2+2

  • Update and migrate iOS example project.

0.6.2+1

  • Specify explicit type for invokeMethod.
  • Use const for Rect.
  • Updated minimum Flutter SDK to 1.6.0.

0.6.2

  • Add optional subject to fill email subject in case user selects email app.

0.6.1+2

  • Update Dart code to conform to current Dart formatter.

0.6.1+1

  • Fix analyzer warnings about const Rect in tests.

0.6.1

  • Updated Android compileSdkVersion to 28 to match other plugins.

0.6.0+1

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.6.0

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.5.3

  • Added missing test package dependency.
  • Bumped version of mockito package dependency to pick up Dart 2 support.

0.5.2

  • Fixes iOS sharing

0.5.1

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.5.0

  • Breaking change. Namespaced the share method inside a Share class.
  • Fixed crash when sharing on iPad.
  • Added functionality to specify share sheet origin on iOS.

0.4.0

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.3.2

  • Fixed Dart 2 type error.

0.3.1

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.3.0

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.

0.2.2

  • Added FLT prefix to iOS types

0.2.1

  • Updated README
  • Bumped buildToolsVersion to 25.0.3

0.2.0

0.1.0

  • Initial Open Source release.