plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: Share.shareXFiles is not working on my Android 11 device but Share.shareFiles is working

Open Tom3652 opened this issue 1 year ago • 20 comments

Platform

Android 11

Plugin

share_plus

Version

6.3.0

Flutter SDK

3.7.6

Steps to reproduce

I am calling :

 await Share.shareFiles([(filePath)], subject: "A nice subject");

And it's working fine, but this method is deprecated.

So i have tried to use :

await Share.shareXFiles([XFile(filePath)], subject: "A nice subject");

And here is the output : PlatformException(Share callback error, prior share-sheet did not call back, did you await it? Maybe use non-result variant, null, null)

With the exact same filePath

The only thing i have found on Google which was not helpful was : https://stackoverflow.com/questions/71855220/flutter-package-share-plus-unexpected-async-await-behaviour but this doesn't seem to match my behavior since it's working with the deprecated method.

Code Sample

call `await Share.shareXFiles([XFile(filePath)], subject: "A nice subject")` and see the error.

Logs

There is nothing helpful so i am attaching the only log i have got : 

`PlatformException(Share callback error, prior share-sheet did not call back, did you await it? Maybe use non-result variant, null, null)`

Flutter Doctor

[✓] Flutter (Channel stable, 3.7.6, on macOS 13.2.1 22D68 darwin-x64, locale fr-FR)
    • Flutter version 3.7.6 on channel stable at /Users/foxtom/Desktop/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12cb4eb7a0 (10 days ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/foxtom/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.76.1)
    • VS Code at /Users/foxtom/Desktop/Visual Studio Code.app/Contents
    • Flutter extension version 3.46.0

[✓] Connected device (3 available)
    • moto g 8 power (mobile) • adb-ZY22BNDW2C-yyjDO7._adb-tls-connect._tcp. • android-arm64  • Android 11 (API 30)
    • macOS (desktop)         • macos                                        • darwin-x64     • macOS 13.2.1 22D68 darwin-x64
    • Chrome (web)            • chrome                                       • web-javascript • Google Chrome 110.0.5481.177

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Checklist before submitting a bug

  • [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

Tom3652 avatar Mar 11 '23 11:03 Tom3652

Try to write the file in File format first and then share. Somehow the XFile() or XFile.fromData() doesn't work as expected. So my workaround to share in image is:

final directoryPath = (await getApplicationDocumentsDirectory()).path;
final imagePath = '$directoryPath/some_image.png';

final imageFile = await File(imagePath).create(recursive: true);
imageFile.writeAsBytesSync(imageContent);

final file = XFile(imagePath);
await Share.shareXFiles([file], text: 'hello');

MuTe33 avatar Mar 19 '23 13:03 MuTe33

Thanks for you help @MuTe33 but it is actually what i did and i am even checking File(filePath).existsSync() before sharing it. I have done exactly the same as you did but get the error anyway. Note : this is working fine on iOS

Tom3652 avatar Mar 19 '23 15:03 Tom3652

I've been using Share.shareXFiles for some time and it worked perfectly but when I upgraded flutter to version 3.7.6, I faced the same error as mentioned.

SheenaJacob avatar Mar 20 '23 07:03 SheenaJacob

Same issue here

final Directory sysTemp = Directory.systemTemp;
final Directory dir = sysTemp.createTempSync();
final String filename = 'my.bkp';

final File temp = File('${dir.path}/$filename');
temp.writeAsBytesSync(utf8.encode(jsonEncode(backup)));
final XFile xfile = XFile(temp.path);
await Share.shareXFiles(<XFile>[xfile], text: filename);
dir.deleteSync(recursive: true);

not working getting the same error

if i replace await Share.shareXFiles with depricated await Share.shareFiles version it works.

c-seeger avatar Apr 04 '23 14:04 c-seeger

This is a regression because it was working with Share.shareXFiles on Android few months ago, i just can't remember which version and don't have time currently to test them one by one.

Tom3652 avatar Apr 07 '23 08:04 Tom3652

I am trying to reproduce the issue using example app and on Flutter 3.7.10. Sharing image works fine for me with Share button which uses shareXFiles(). Could you specify which types of files fail to share for you?

vbuberen avatar Apr 16 '23 19:04 vbuberen

It seems to be working again using flutter 3.7.10 + on the same phone that had the issue, so this issue is possible to be happening only on Flutter 3.7.6 as mentioned by the other comments.

Tom3652 avatar Apr 17 '23 15:04 Tom3652

Thanks for the feedback.

@SheenaJacob @c-seeger Could you confirm that updating Flutter version helps with the issue?

vbuberen avatar Apr 18 '23 07:04 vbuberen

In my case, I was able to resolve the above issue by changing the share_plus version from 7.0.2 to 7.0.0. Additionally, I am using Flutter SDK version 3.7.11.

jinal-dev avatar Jun 16 '23 10:06 jinal-dev

I am having the same issue. share_plus 7.0.2 and flutter 3.10.2

InspectlyMads avatar Jun 20 '23 08:06 InspectlyMads

@InspectlyMads,
Have you considered downgrading the share_plus version and using that version? This might help you to resolve the issue. Sometimes, compatibility issues can arise with different versions of packages. By downgrading to a previous version, you may be able to regain the share functionality.

jinal-dev avatar Jun 21 '23 06:06 jinal-dev

I'm having the same problem. Note: Fixed by changing the version to 7.0.0

Aksoyhlc avatar Aug 11 '23 13:08 Aksoyhlc

This is a serious issue, and need to be fixed, I'm having the same problem with latest version.

swarupbc avatar Sep 05 '23 12:09 swarupbc

To solve the issue we need a reproducing instructions/reproducer project. I have already mentioned some months ago that currently can't reproduce. So till there is a proper reproducer provided we can't really help with this issue.

vbuberen avatar Sep 06 '23 08:09 vbuberen

same issue when using version 7.1.0

putrautama007 avatar Oct 04 '23 11:10 putrautama007

same, but shareFiles works

ogios avatar Oct 23 '23 14:10 ogios

same issue here

erperejildo avatar Nov 18 '23 09:11 erperejildo

Same issue here (downgrading to version 7.0.0 didn't work).... @vbuberen to reproduce the issue try the steps listed here friend: https://github.com/fluttercommunity/plus_plugins/issues/1936

RamiroGarrido avatar Nov 22 '23 20:11 RamiroGarrido

Share.shareFiles works fine, but the same issue occurs with Share.shareXfiles.

Jay-Pyo avatar Dec 11 '23 16:12 Jay-Pyo

To solve the issue we need a reproducing instructions/reproducer project. I have already mentioned some months ago that currently can't reproduce. So till there is a proper reproducer provided we can't really help with this issue.

the reproducible steps are (Android):

  1. have shareXFiles e.g. on some button click)
      await Share.shareXFiles(
        filesToShare, // e.g. 1 pdf
        text: 'Sharing something',
      );
  1. In the share sheet, pick the same app as you are sharing from -- it needs to be used with https://pub.dev/packages/share_handler
  2. Try to share again

mzdm avatar Jan 04 '24 16:01 mzdm

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

github-actions[bot] avatar Apr 04 '24 00:04 github-actions[bot]