Flutter’s SharePlus plugin is refusing to share images, complaining
PlatformException(Share failed, assets/slideshow/tom_riddle_harry_potter_tour.webp: The source file doesn’t exist., null, null)
The source file does exist, it’s correctly declared in pubspec.yaml, and displayed in the app elsewhere using Image.asset(...
using the same path.
I’ve tried numerous things, I tried giving XFile the MimeType, that didn’t work.
I thought ‘maybe it just won’t work on web’, so I eliminated image sharing in the web app.
Well that got sharing in the web app working, using a fallback, but the problem persisted on Android. So I tried omitting the image’s path; just using the file name (with extension). Nope.
I tried specifying the image path string in a different manner, shouldn’t work, didn’t.
I tried reading the code for XFile and so far as I can see instantiating an XFile using an image path is perfectly valid.
Share.shareXFiles([XFile("assets/slideshow/${presentLocation.pictureList[0]}",
mimeType: "image/webp",
name: presentLocation.name.split(".")[0])],
subject: presentLocation.name + presentLocation.emoji,
text: shareStr,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size).then((shareResult) async =>
{
if (shareResult.status ==
ShareResultStatus.success)
{
await MyApp.analytics.logShare(
contentType: "URL shared",
itemId: presentLocation.name,
method: "with image")
}
});
Am I misunderstanding XFile? What should I do?
2
Answers
Try this,
To create temporary directory,
path-provider
package might be needed if you already don’t have it.https://pub.dev/packages/path_provider
One may also attempt to directly utilize the XFile.fromData code, as it does not necessitate any extra reliance on path-provider.