Closed mdublin closed 4 months ago
Can you reproduce the same issue in the example
app and share the code with reproducer?
I have assumptions that it might be something related to the context you provide.
@vbuberen I have not tried that yet, it wouldn't be trivial to recreate what we're doing with the example app unfortunately. But I can confirm that the values from the context we're passing to sharePositionOrigin
are:
Offset = 0.0, 0.0. Size= 1024.0, 1366.0
The above values are what I get when inspecting box.localToGlobal(Offset.zero)
and box.size
from:
final RenderRepaintBoundary box = _globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
Also, I updated my code sample and included the code for the captureWidget
code if that helps.
I am experiencing the same issue.
I debugged the view in Xcode and it seems the SHSheetSceneViewController
UIView
has a width and height set to 0 for iPads,
whereas on an iPhone 15 Pro, it shows the width and height set respectively to 393 and 852
iPad | IPhone 15 Pro |
---|---|
One way to fix this problem is to set the popoverPresentationController.sourceRect to a size smaller than the holding controller:
Example: in FPPSharePlusPlugin:405
if (!CGRectIsEmpty(origin)) {
activityViewController.popoverPresentationController.sourceRect = origin;
// See below the line I added
activityViewController.popoverPresentationController.sourceRect = CGRectMake(controller.view.bounds.size.width / 2.0, controller.view.bounds.size.height - 50, 1.0, 1.0);
}
This change starts showing the popOverViewController
It means that playing around with the origin value should be able to work
UPDATE:
Setting sharePositionOrigin to:
final box = context.findRenderObject() as RenderBox?;
final sharePositionOrigin = Rect.fromLTWH(box.size.width / 2, box.size.height - 50, 1, 1);
allows showing a popOverController pointing to the center and 50 points to the bottom of the screen.
The same issue occurs.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)]
Unhandled Exception: PlatformException(error, sharePositionOrigin: argument must be set, {{0, 0}, {1194, 834}} must be non-zero and within coordinate space of source view: {{0, 0}, {6, 0}}, null, null)
As shown in the error above, the height of the source view is set to 0.
One strange thing is that if you press the Share button and rotate the simulator horizontally or vertically while an error occurs, the normal action is executed.
https://github.com/fluttercommunity/plus_plugins/assets/9462045/ae200f2f-daad-42d8-a6e2-0abd8241b5d0
Experiencing the same problem, trying to share a log file on an iPad: initially nothing happens when calling Share.shareXFiles(). Changing orientation right after suddenly does pop up the share dialog.
Method I'm using:
Future _shareFile(BuildContext context, String path, String body) async {
final box = context.findRenderObject() as RenderBox?;
await Share.shareXFiles(
[XFile(path)],
text: body,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
}
EDIT:
It seems in my case the sharePositionOrigin from the share_plus plugin readme doesn't work and throws the following exception:
PlatformException(error, sharePositionOrigin: argument must be set, {{0, 0}, {1573.3333333333333, 820}} must be non-zero and within coordinate space of source view: {{0, 0}, {1180, 820}}, null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
<asynchronous suspension>
#2 MethodChannelShare.shareFilesWithResult (package:share_plus_platform_interface/method_channel/method_channel_share.dart:140:9)
<asynchronous suspension>
#3 _InfoDialogState._shareFile (package:hotos/ui/widgets/dialogs.dart:310:5)
<asynchronous suspension>
Changing the sharePositionOrigin to the following works:
Future _shareFile(BuildContext context, String path, String body) async {
final size = MediaQuery.of(context).size;
await Share.shareXFiles(
[XFile(path)],
text: body,
sharePositionOrigin: Rect.fromPoints(
Offset.zero,
Offset(size.width / 3 * 2, size.height),
),
);
}
@kazume this at least solves the problem of the error and it not appearing at all on iPad, just need to tweak it to get it to show up in the right spot/be the right size. Wish they could just fix this though.
I mean, you are supposed to provide a valid sharePositionOrigin
, that's something the plugin cannot do for you.
I mean, you are supposed to provide a valid
sharePositionOrigin
, that's something the plugin cannot do for you.
Fair enough, it's just that the example as posted on the readme page of the plugin doesn't work for me :P That's a bit tricky, since you don't expect the error to be in code posted on the readme site of the plugin :) Not having a go, just pointing out :)
Yep, it is fairly complicated. I think there is room for improvement in the plugin documentation.
The example works because it takes the context of a Builder
wrapping the button, so the render box points to the right place.
As you can see, there is a Builder
wrapping the share button: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/share_plus/share_plus/example/lib/main.dart#L146
I could imagine many users are simply copying that section but ignoring where this context comes from, and using the top widget context, which won't work as expected.
Ye, totally. I missed that one as well. I just implemented sharing a log file, so a typical "I'll put that in real quick, while already moving on the the next "real" issue in mind" thing. It's a textbook example of what we like to call the shortest computer joke: "let's do that real quick".
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
reopen
Platform
iOS 16.1, iPad Pro 6th Generation
Plugin
share_plus
Version
7.2.1
Flutter SDK
3.16.3
Steps to reproduce
Trying to implement share_plus on our project, and on iPad we were seeing the following error when our share button was touched:
We researched the issue and added the
sharePositionOrigin
parameter and are passing it thebox!.localToGlobal(Offset.zero) & box.size
value. We are attempting to use the recommendedsharePositionOrigin
parameter as described here.However, that doesn't seem to work, and now just nothing happens. There is no exception or error message, we just see in the log where the screenshot gets created and then....nothing.
Code Sample
Logs
Flutter Doctor
Checklist before submitting a bug
flutter pub upgrade
flutter clean