[Bug]: Sharing an image on Windows is not working
Platform
Windows
Plugin
share_plus
Version
10.1.4
Flutter SDK
3.29.0
Steps to reproduce
share an image file and observe the poping window. it's showing a loading circle indicator then dismissed. The second time it won't show anymore.
Code Sample
Use this code to share an image file on the disk:
Share.shareXFiles(
[XFile(path)], subject: "some subjects",
);
Logs
No useful logs
Flutter Doctor
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [版本 10.0.19045.5487], locale zh-CN) [258ms]
• Flutter version 3.29.0 on channel stable at C:\Users\Administrator\fvm\versions\3.29.0
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 35c388afb5 (3 weeks ago), 2025-02-10 12:48:41 -0800
• Engine revision f73bfc4522
• Dart version 3.7.0
• DevTools version 2.42.2
[√] Windows Version (10 专业版 64-bit, 22H2, 2009) [674ms]
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,632ms]
• Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29)
• All Android licenses accepted.
[√] Chrome - develop for the web [55ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.2) [54ms]
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.12.35521.163
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2024.2) [10ms]
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29)
[√] VS Code (version 1.95.3) [9ms]
• VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.104.0
[√] Connected device (4 available) [185ms]
• ALN AL80 (mobile) • 2MM0223B23004971 • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.0.19045.5487]
• Chrome (web) • chrome • web-javascript • Google Chrome 133.0.6943.142
• Edge (web) • edge • web-javascript • Microsoft Edge 133.0.3065.82
[√] Network resources [600ms]
• All expected network resources are available.
Checklist before submitting a bug
- [x] I searched issues in this repository and couldn't find such bug/problem
- [x] I Google'd a solution and I couldn't find it
- [x] I searched on StackOverflow for a solution and I couldn't find it
- [x] I read the README.md file of the plugin
- [x] I'm using the latest version of the plugin
- [x] All dependencies are up to date with
flutter pub upgrade - [x] I did a
flutter clean - [x] I tried running the example project
i'm facing issue to share pdf file on windows, getting "ShareResultStatus.unavailable" error
ShareResultStatus.unavailable is not an error, that just indicates that the share result is unknown.
I'd advise checking with v11 of the plugin, as the implementation was refactored.
after update to latest version, unable to share file on windows 11, previously it was working, then how to share file on windows 11?
is this bug or issue from my side?
I've encountered this problem before (https://github.com/fluttercommunity/plus_plugins/issues/3197)
For some reason share_plus is not able to work with xFile just like that. It needs to be saved in a clear path so that share_plus can access it. Otherwise it tries to send something that doesn't exist.
I'm not sure if this requires an update to the documentation, or still some sort of solution to this problem on the share_plus side.
This is the code that gets around the problem:
var temp = (await getTemporaryDirectory()).path;
final filePath = path.join(temp, name);
var file = File(filePath);
await file.writeAsBytes(bytes);
await SharePlus.instance.share(
ShareParams(files: [XFile(filePath)]),
);
@miquelbeltran, last time you answered similarly about ShareResultStatus.unavailable, however we are not interested in getting the share status, but just to share the file. And it doesn't work, without the manipulation above not being obvious. This looks like a bug that needs to be either fixed or at least explained in the documentation.
It needs to be saved in a clear path so that share_plus can access it. Otherwise it tries to send something that doesn't exist.
Ah, thanks, that's probably why I didn't see the problem when I did my tests.
To help me understand this problem better, what would be an example of a file path that fails and an example of a file path that works?
Copying the file into a temporal directory is what we already do internally when you use XFile.fromData, because the file.path would be empty.
https://github.com/fluttercommunity/plus_plugins/blob/c8c1a143ee61c635ce1a34c4cfc34b8d9654a811/packages/share_plus/share_plus_platform_interface/lib/method_channel/method_channel_share.dart#L81-L89
Maybe the solution is to simply always copy the file into the temporal directory, no matter if you provided a path or not.
last time you answered similarly about
ShareResultStatus.unavailable, however we are not interested in getting the share status, but just to share the file.
The thing is that people get confused by the responses' status name, so I need to clarify every time that unavailable != bug or error.
i used await SharePlus.instance.share( ShareParams( files: [ XFile( AppConstants.isWindows() ? filePath.replaceAll("/", "\") : filePath, ), ], ), ); filepath is a windows temporary directory file, why it's not workng
share some sample code to share file on windows
@selvam920, do you happen to have the temporary file deleted after the save is complete?
It's just that await on share on Windows doesn't work. Accordingly, functions after await are executed immediately, not waiting for the send process to complete.
Judging by your screenshots, share on Windows menu is trying to load a file that doesn't exist anymore.
can you check it's simple example
same thing is working with previous version 10.1.4
@selvam920, as I wrote in https://github.com/fluttercommunity/plus_plugins/issues/3558, you also need to give the text parameter, it won't work without it.
when i provide text in the ShareParams, it's share only text without file
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days