-
-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: share_plus Share.shareXFiles() is not working on web #1643
Comments
I got the same error message when I create a XFile with image data, and then share it by 'shareXFiles' function |
I got the same error message on Chrome 113 on iOS 16.4.1 (iPhone):
|
Same here! I am using |
Same issue here! Sample code that uses PictureRecorder to generate a png from canvas
followed the example plus_plugins/packages/share_plus/share_plus/example/lib/main.dart Lines 243 to 252 in b6888ed
still getting
|
Tried on Safari and Edge also, none worked. |
Seconding this is an issue for me. My code sample:
Any plans for fixing or workarounds? |
I have the same problem, has anyone solved it? |
I think the issue is that web browsers do not have a native share menu like mobile devices have. However, you can download single files. Here is an example: await XFile.fromData(
Uint8List.fromList(/* some mp3 data */),
mimeType: 'audio/mpeg',
).saveTo('my-file-name.mp3'); |
@dongnqdev would you mind sharing your implementation? |
@xonaman Yes, This is my code. If you wonder where is the bytes came from. It was data converted from Widget to Image. And it works well on android and iOS. Btw, I have a question doesn't relates to this topic. But does ShareResult.raw provides us any information about the option that user have chosen? For example, save to device or name of the selected application (twitter x,....). Thanks
This is my doctor -v, and I'm using share_plus: ^7.2.1
|
The documentation mentions the following: /// Share [XFile] objects.
///
/// Remarks for the web implementation:
/// This uses the [Web Share API](https://web.dev/web-share/) if it's
/// available. Otherwise, uncaught Errors will be thrown.
/// See [Can I Use - Web Share API](https://caniuse.com/web-share) to
/// understand which browsers are supported. This builds on the
/// [`cross_file`](https://pub.dev/packages/cross_file) package. The code essentially all does is to call to One improvement that could be done is using the One thing you can try as well is setting the |
@miquelbeltran Thank for your response. I did check the version of safari before posting my issue. My iPhone is running 17.3.1, so the safari on my phone is supported.
|
@miquelbeltran Hi Miquelbentran I have tried to specify the mimeType, but still got the same problem. This is my code.
This is StackTrace
|
That doesn't look correct --> |
@miquelbeltran Yes, I tried the |
same issue, flutter: 3.16.9 |
You can use MemoryFileSystem for web and LocalFileSystem for mobile from https://pub.dev/packages/file. final FileSystem _fileSystem = kIsWeb ? MemoryFileSystem() : const LocalFileSystem(); See their example to create a file https://github.com/google/file.dart/blob/master/packages/file/example/main.dart. You can than pass this file's path and basename into an XFile. XFile(
file.path,
name: file.basename,
) But for now the Share sheet for me is only shown in Safari (not Chrome, not Firefox). So as a fallback you can have a download action. import 'package:universal_html/html.dart' as html;
final result = await Share.shareXFiles(
[
XFile(
file.path,
name: file.basename,
),
],
subject: "Subject",
text:
"Text",
// required for iPads, see https://pub.dev/packages/share_plus
sharePositionOrigin: (context.findRenderObject() as RenderBox?)!
.localToGlobal(Offset.zero) &
(context.findRenderObject() as RenderBox?)!.size,
);
// Web fallback if Share API is not available
if (result.status == ShareResultStatus.unavailable && kIsWeb) {
final url =
"data:application/pdf;base64,${base64Encode(await file.readAsBytes())}";
try {
final html.AnchorElement anchorElement =
html.AnchorElement(href: url);
anchorElement.download = model.fetchedPDFFile!.basename;
anchorElement.click();
anchorElement.remove();
} catch (e) {
await launchUrl(
Uri.parse(
url,
),
);
}
} |
The documentation states However, this fallback does not seem to be working, which in my opinion is a bug. It can also be easily fixed with proper fallback handling. Below is some code that works great for me, using the universal html package.
|
Yeah, looking at the code seems that it was removed (or even never implemented?). Anyway, if you want, you can submit a PR with the change... Or the README should be corrected. |
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 |
@miquelbeltran would you you be okay with fallback implementation using something along the lines of @hamishjohnson example in #1643 (comment) ? |
It makes sense to me! |
Platform
Chrome web browser on MacOS
Plugin
share_plus
Version
latest from the main
Flutter SDK
3.7.8
Steps to reproduce
Code Sample
Logs
Flutter Doctor
Checklist before submitting a bug
flutter pub upgrade
flutter clean
The text was updated successfully, but these errors were encountered: