Mobile Development8 min read
Share in Flutter: Text, Files and Links
Share text, links and files from your Flutter app with share_plus: open the share sheet, handle iPad anchors, share files you create, and read the result.
- #flutter
- #share-plus
- #sharing
- #files
- #plugins

Almost every app eventually needs a share button. A user wants to send a link to a friend, export a report, or save a photo to their files. On Android and iOS that means opening the system share sheet — the same sheet every native app uses — and in Flutter the maintained way to do it is the share_plus package. One call opens the sheet, the user picks the destination, and your app never has to know which apps are installed. This guide covers the whole flow: sharing text and links, sharing one or more files, adding a subject, reading the result, and the two platform traps that catch most developers — the iPad anchor rectangle and files that live in private storage. The code targets current stable Flutter and Dart, uses the share_plus 10 API, and needs no native code of your own.
Why use share_plus to share in Flutter?
Use share_plus because it is the maintained, community-supported sharing plugin for Flutter, and it opens the native share sheet on Android and iOS from a single Dart API. It is the official successor to the old share plugin, maintained under the Flutter Community Plus Plugins project, and it is the package the Flutter ecosystem converged on: one call handles text, links, and files, with the same behaviour on both platforms. Building the same feature with platform channels means writing Kotlin and Swift, wiring a MethodChannel, and maintaining two native implementations for a sheet the operating system already provides.
| Approach | What you get | When to use it |
|---|---|---|
| share_plus | Native share sheet for text, links, and files from one Dart API | Almost always: the fastest path to a working share button |
| url_launcher | Opens a URL in another app or the browser | You want to open a link directly, not offer the user a choice of destinations |
| Platform channels | Full control over the native share intent | You need behaviour the plugin does not expose, such as a custom share target list |
| The share sheet is also the honest way to share. Your app hands content to the operating system, the user sees exactly what leaves the phone, and the user picks the destination. That matters for privacy: nothing is uploaded, nothing is sent in the background, and the user stays in control. The same principle shapes privacy-first offline apps, where data leaves the device only when the user asks it to. |
Step 1: add the package
Add share_plus to pubspec.yaml. The path_provider package comes in later in this guide, when the app creates a file and then shares it.
dependencies:
flutter:
sdk: flutter
share_plus: ^10.0.0
path_provider: ^2.1.0
No native setup is needed. On Android the plugin bundles its own FileProvider configuration, so sharing a file does not require manifest changes. On iOS there is no Info.plist entry for sharing. Run flutter pub get and the plugin is ready. The package page at pub.dev/packages/share_plus lists the current version and the supported platforms.
Step 2: share text and links
Sharing text is one call. Pass the text to ShareParams and hand it to SharePlus.instance.share, which opens the native share sheet. A link is just text as far as the sheet is concerned, so the same call shares a URL, a referral code, or a plain message. The subject is picked up by email clients; most messaging apps ignore it, so put anything essential in the text itself.
import 'package:share_plus/share_plus.dart';
Future<void> shareAppLink() async {
await SharePlus.instance.share(
ShareParams(
text: 'Try this app: https://example.com/app',
subject: 'An app you might like',
),
);
}
Wire that function to a button and you have a working share feature. A common place to use it is after a user finishes something worth passing on: a scanned code, a generated result, or a completed workout. The guide to building a QR code scanner in Flutter ends with a scanned value that the user often wants to share, and this is the call that does it.
Step 3: share files
Sharing a file works the same way, with the file passed as an XFile in the files list. Give each file a mimeType so the receiving app knows what it is getting — image/jpeg for a photo, application/pdf for a PDF, text/plain for a text file. You can share several files at once by adding more entries to the list, and you can combine files with text, for example a caption alongside a photo.
Future<void> sharePhoto(String imagePath) async {
await SharePlus.instance.share(
ShareParams(
files: [XFile(imagePath, mimeType: 'image/jpeg')],
text: 'Here is the photo from my trip.',
),
);
}
Two rules keep file sharing reliable. First, the file must exist at the path you pass — check it before sharing, because a missing file fails silently on some devices and shows an empty sheet on others. Second, share a file your app can actually hand over: a path inside the temporary directory or the app documents directory works, because the plugin serves it through a content provider on Android and a file coordinator on iOS. Never pass a path from another app's private storage; the receiving app cannot read it and the share will fail.
Step 4: share a file your app just created
Many apps do not share an existing file — they create one and share it immediately. A report, an exported backup, or a generated image all follow the same pattern: write the file to the temporary directory with path_provider, then share it. Files in the temporary directory are fine to share, and the operating system may clean them up later, so you do not need to manage deletion yourself.
import 'dart:io';
import 'package:path_provider/path_provider.dart';
Future<void> shareReport(String reportText) async {
final directory = await getTemporaryDirectory();
final file = File('${directory.path}/report.txt');
await file.writeAsString(reportText);
await SharePlus.instance.share(
ShareParams(
files: [XFile(file.path, mimeType: 'text/plain')],
subject: 'Monthly report',
),
);
}
This pattern is also how a health or finance app lets a user send their data somewhere useful. HerCycle, for example, builds a cycle health report the user can share with their doctor — the same idea of a user-initiated export, where the user taps share and picks the destination, instead of the app uploading anything on its own. A QR code can carry the same idea in the other direction: the secure QR medical profile shares emergency details instantly through a code the user chooses to show.
Step 5: read the share result
The share call returns a ShareResult, and its status tells you what happened — with one platform difference that matters. On iOS the status is success when the user picks a destination and dismissed when the user closes the sheet. On Android the status is always unavailable, because Android does not report whether the user completed the share. Never gate app logic on the result: do not mark an item as shared, do not delete the file, and do not show a success message based on it.
Future<void> shareWithFeedback(String text) async {
final result = await SharePlus.instance.share(
ShareParams(text: text),
);
if (result.status == ShareResultStatus.dismissed) {
// The user closed the sheet without sharing (iOS only reports this).
return;
}
// On Android the status is unavailable, so treat the call as fire-and-forget.
}
The result is useful for analytics and for deciding whether to show a hint, not for confirming a delivery. If your feature needs proof that content arrived — a sent email, a delivered message — sharing is the wrong tool, because the share sheet deliberately keeps that information from your app.
The iPad trap: sharePositionOrigin
The most common crash in Flutter sharing happens only on iPad. On iPad the share sheet appears as a popover anchored to a rectangle on screen, and if you do not supply that rectangle the app crashes. Pass the position of the button that triggered the share, using its RenderBox, and the popover anchors to it. Phones ignore the rectangle, so the same code is safe everywhere.
Future<void> shareFromButton(BuildContext context, String text) async {
final box = context.findRenderObject() as RenderBox?;
await SharePlus.instance.share(
ShareParams(
text: text,
sharePositionOrigin: box == null
? Rect.zero
: box.localToGlobal(Offset.zero) & box.size,
),
);
}
Call this from the button's own BuildContext so the rectangle matches the button's position. The single most reliable habit is to always pass sharePositionOrigin from the triggering widget, even in an app you only plan to ship on phones — the day someone runs it on an iPad, the share button keeps working instead of crashing.
What usually goes wrong
Most share_plus problems come from the same short list. The iPad crash above is first: no sharePositionOrigin, no popover anchor, and the app dies. Second is a file path that does not exist, or a path in private storage the receiving app cannot read — write the file to the temporary directory first, as in Step 4. Third is expecting a reliable shared confirmation on Android, which the platform simply does not provide; treat the call as fire-and-forget and keep any confirmation UI out of the flow. Fourth is the old static API: Share.share and Share.shareXFiles still exist in share_plus 10, but they are deprecated in favour of SharePlus.instance.share with ShareParams, and new code should use the instance API. Fifth is sharing very large files, such as uncompressed images, without a mimeType — the receiving app may refuse a file it cannot identify, so always set the type. None of these need native code to fix. They are all Dart-side habits: anchor the popover, check the file, set the mimeType, and use the current API.
Key takeaways
Sharing in Flutter is a solved problem once the right habits are in place. One package opens the native sheet on both platforms, the user picks the destination, and your app stays out of the way. Add the package, share text with one call, share files with XFile and a mimeType, create-then-share for exports, and always anchor the popover on iPad. Treat the result as a hint, not a delivery receipt, and the feature will work the same on every device your users own. Get in touch and let's talk about your project.
Frequently asked questions
- How do I share a link in Flutter?
- Add the share_plus package and call SharePlus.instance.share with ShareParams containing the link as text. The native share sheet opens and the user picks the destination app.
- How do I share a file in Flutter?
- Pass the file as an XFile with a mimeType in the files list of ShareParams, for example XFile(path, mimeType: image/jpeg). The file must exist in a location the receiving app can read, such as the temporary directory.
- Why does my Flutter app crash when sharing on iPad?
- On iPad the share sheet is a popover anchored to a rectangle on screen. Pass sharePositionOrigin from the triggering button using its RenderBox, or the app crashes. Phones ignore the rectangle, so the same code is safe everywhere.
- Can I tell whether the user actually shared something?
- Only partly. On iOS the result reports success or dismissed, but on Android the status is always unavailable because Android does not report the outcome, so never gate app logic on the share result.


