plus_plugins
plus_plugins copied to clipboard
[Bug]: prior share-sheet did not call back, did you await it? Maybe use non-result variant
Platform
android 10
Plugin
share_plus
Version
6.2.0
Flutter SDK
3.0.4
Steps to reproduce
call this
const logFileName = 'log.txt';
Future<String> get logFilePath async =>
'${await getApplicationDocumentsDirectory().then((value) => value.path)}/$logFileName';
Share.shareXFiles([XFile(await logFilePath)])
Code Sample
No response
Logs
E/flutter (13841): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(Share callback error, prior share-sheet did not call back, did you await it? Maybe use non-result variant, null, null)
E/flutter (13841): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:607
E/flutter (13841): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:167
E/flutter (13841): <asynchronous suspension>
E/flutter (13841): #2 MethodChannelShare.shareFilesWithResult
package:share_plus_platform_interface/method_channel/method_channel_share.dart:134
E/flutter (13841): <asynchronous suspension>
E/flutter (13841):
Flutter Doctor
[✓] Flutter (Channel stable, 3.0.4, on macOS 12.5.1 21G83 darwin-arm, locale en-UA)
• Flutter version 3.0.4 at /Users/illia/Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 85684f9300 (5 months ago), 2022-06-30 13:22:47 -0700
• Engine revision 6ba2af10bb
• Dart version 2.17.5
• DevTools version 2.12.2
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
I was facing the same issue on Android 12.
Code:
Future<void> exportData() async {
final String jsonString = jsonEncode(toJson());
// Create a temporary file
final directory = await pathProvider.getTemporaryDirectory();
final File jsonFile = File(
'${directory.path}/portarius_backup_${_parseTime(DateTime.now())}.json');
await jsonFile.writeAsBytes(jsonString.codeUnits);
final XFile file = XFile(jsonFile.path);
ShareResult result = await Share.shareXFiles(
[file],
text: 'Portarius backup',
subject: 'Portarius backup',
);
if (result.status != ShareResultStatus.success) {
_logger.e('Error sharing file: ${result.status}');
}
// Delete the temporary file
await jsonFile.delete();
}
I fixed it by rebuilding the app (and cold booting the VM)—no clue what caused it or if it'll happen again.
I'm having the same issue, did you find any solution?
Having the same issue at my end, the share bottom sheet doesn't open and falls back to the exception as mentioned above by @IlyaMax
Use case: I have used shareXFiles()
method to share multiple images and text on WhatsApp and tried making it a async-await call as mentioned in the logs.
Flutter SDK: 3.3.10 Android 8.0.0 (API 26)
Please resolve it as soon as possible.
Same problem, Ios fine, only Android
Same here! Let me know if you have a fix. Cheers
I have faced the same problem, but mine was sharing after moving a file from the private folder to the Download folder. The solution for me was to first turn the path in a File and then use this file's path to make a new XFile.
After downloading, I moved the file to the Download Folder and was trying to create a new XFile from the moved file's path, which did not work. I then created a new File with that same path and used it's path and it worked. Maybe there is something hidden in the File creation process, but I hope this can help!
Future<String> downloadMethod() {
final Response response = await _dio.get(
url,
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
),
);
final file = await _createFile(fileName);
final uniqueFileName = _getFileName(file.path);
_writeFile(file, response);
await moveDownloadedFilesToDownloadDirectory([file.path]);
final movedFilePath =
_mediaStoreWrapper.getCompleteFilePath(fileName: uniqueFileName);
final movedFile = File(movedFilePath);
return movedFile.path;
}
My share implementation was then:
final paths = filePathList
.map(
(filePath) => XFile(filePath),
)
.toList(growable: false);
final result = await Share.shareXFiles(
paths,
subject: subjectText,
text: messageText,
);
It worked like this :)
Facing the same issue, any follow-ups?
- android 12
- share plus 6,3,1
in my case am getting the following error: PlatformException (PlatformException(Share callback error, prior share-sheet did not call back, did you await it
when using below code:
final XFile file = XFile(path);
await Share.shareXFiles([file],
but if I use the deprecated method like below (passing the List<String>, the sharing of image works perfectly: await Share.shareFiles([path], subject: subject, text: text, sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
shareFiles is marked as deprecated but works fine, while following documentation and using shareXFiles, throws the plaform exception error: My environment: Flutter 3.7.10 • channel stable • https://github.com/flutter/flutter.git Framework • revision 4b12645012 (9 days ago) • 2023-04-03 17:46:48 -0700 Engine • revision ec975089ac Tools • Dart 2.19.6 • DevTools 2.20.1
Based on my understanding, it appears that the occurrence is triggered by multiple calls. Therefore, I have taken the initiative to include a loader in order to prevent the issue from arising due to such repeated calls.
Based on my understanding, it appears that the occurrence is triggered by multiple calls. Therefore, I have taken the initiative to include a loader in order to prevent the issue from arising due to such repeated calls.
Could you elaborate more?
-> Show loader -> Share functionality -> Dismiss loader
-> Show loader -> Share functionality -> Dismiss loader
give an example
I am currently facing an issue where I am unable to share images on iOS devices. I need to fix this problem. Please let me know if it would be fine.
any solution?
In android 12/13 im getting this same issue but in previous versions its just working fine..
I fixed the error by ensuring that I used the "await" keyword when calling my use case, which contains all the shared logic. Initially, I neglected to include "await" in the first call.
yeah,use await at first
I was able to resolve this issue by downgrading share_plus version from 7.0.2 to 7.0.0.
Code:
`final directoryPath = (await getTemporaryDirectory()).path;
final imagePath = '$directoryPath/qrimg.png';
final imageFile = await File(imagePath).create(recursive: true);
imageFile.writeAsBytesSync(byteData.buffer.asUint8List());
final file = XFile(imagePath);
await Share.shareXFiles([file]);`
Flutter SDK - 3.7.11 Android version 12
final Directory temporaryDirectory = await getTemporaryDirectory();
/// getTemporaryDirectory() is from path_provider
final String path = "${temporaryDirectory.path}/image.jpg";
File(path).writeAsBytesSync(qrImage!);
/// Type of qrImage is Uint8List
await Share.shareXFiles([XFile(path)]);
this solution worked for me Hope this will work for you too.
final Directory temporaryDirectory = await getTemporaryDirectory(); /// getTemporaryDirectory() is from path_provider final String path = "${temporaryDirectory.path}/image.jpg"; File(path).writeAsBytesSync(qrImage!); /// Type of qrImage is Uint8List await Share.shareXFiles([XFile(path)]);
this solution worked for me Hope this will work for you too.
This worked for me! Thanks!
I fixed it by rebuilding the app (and cold booting the VM)—no clue what caused it or if it'll happen again.
Cold reboot emu helped me too.
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
Same error on real device. Android
Fix by blocking multiple calls to share method.
Example you have image share button & user clicks it multiple time.
Fix by blocking multiple calls to share method.
Example you have image share button & user clicks it multiple time.
@glintpursuit This solution working ok
I'm already using await and there's no way anyone else would call this function simultaneously since it's a button click handler and I'm not rage clicking. I have a suspicion that there's a lock file or mutex which left open somehow from one of my previous interrupted debug sessions and the Android native stack thinks now permanently that it's in a call? Is that possible? Yesterday this was working fine for me.
I have a suspicion that there's a lock file or mutex which left open somehow from one of my previous interrupted debug sessions and the Android native stack thinks now permanently that it's in a call? Is that possible?
Take a look at the open pr #2817 which throws some light on the problem with the ShareSuccessManager
implementation getting deadlocked.
Essentially, a further call to the share files while the previous share file call hasn't returned will cause the second call to be ignored. The problem is that a failed first call would cause the plugin to be in a bad state. The changes in the linked PR try to address that. If we see that those changes are insufficient, we will have to rethink the implementation of ShareSuccessManager
and/or remove the "result" from the share operation to allow multiple calls.
Take a look at the open pr #2817 which throws some light on the problem with the
ShareSuccessManager
implementation getting deadlocked.Essentially, a further call to the share files while the previous share file call hasn't returned will cause the second call to be ignored. The problem is that a failed first call would cause the plugin to be in a bad state. The changes in the linked PR try to address that. If we see that those changes are insufficient, we will have to rethink the implementation of
ShareSuccessManager
and/or remove the "result" from the share operation to allow multiple calls.
Essentially a lot of people here I'm sure don't call the share simultaneously, and probably have await as me, and possibly ran into that behavior you mention. The question is that as a workaround how can you make the system "snap out of it"?
The question is that as a workaround how can you make the system "snap out of it"?
Not really a workaround, but rather correctly restarting the state of the ShareSuccessManager
As a "hack", you can provoke an error (e.g. attempting to share a non-existing file) and that resets the state when an error occurs.
If after that we still get reports regarding this issue, then I will reimplement the ShareSuccessManager
from scratch, or maybe even remove the "result" functionality from the share methods, because I think having a stable package is more important than having that functionality.
I was able to snap out of it by making code changes. I didn't do any flutter clean.