I am using the "share_plus" Flutter library to share a file with a Firebase dynamic link. Here is the code I am currently using:
...............
final dynamicLink =
await FirebaseDynamicLinks.instance.buildShortLink(dynamicLinkParams);
var description = 'Check this out on our app ${dynamicLink.shortUrl}';
Share.shareXFiles([XFile(fileName)], text: description).then((value) async {
setState(() {
shareCount += 1;
});
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.remove("sharedPostId");
Navigator.pop(context);
});
.................
On Android, the share bottom sheet opens fine. However, on iOS, the share bottom sheet does not open, and the logs display the following error message:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, sharePositionOrigin: argument must be set, {{0, 0}, {0, 0}} must be non-zero and within coordinate space of source view: {{0, 0}, {414, 736}}, null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:315)
<asynchronous suspension>
#2 MethodChannelShare.shareFilesWithResult (package:share_plus_platform_interface/method_channel/method_channel_share.dart:134)
Any help will be greatly appreciated!
if your are using Share_Plus plugin in flutter:
I solved it by adding sharePositionOrigin: Rect.fromLTWH(0, 0, screenWidth, screenHeight) in the shareUrl() function This is my code:
......................................................
void shareUrl(String text, BuildContext context){
try{
Size size = MediaQuery.of(context).size;
double screenWidth = size.width;
double screenHeight = size.height;
Share.share(text,
sharePositionOrigin: Rect.fromLTWH(0, 0, screenWidth,
screenHeight));
} catch (e) {
Get.snackbar('Error', 'Failed to share: $e');
}
}
....................................................
I hope its helps.