Skip to content

Conversation

@alexmercerind
Copy link
Contributor

@alexmercerind alexmercerind commented Oct 10, 2022

Description

This pull-request fixes an issue where calling Share.shareXFiles caused stack-overflow due to an endless recursion cycle on:

  • Windows 10 builds lower than 17763.
  • Linux.

Now shareXFiles has been overrided in both ShareLinux & ShareWindows classes, to correctly throw UnimplementedError instead. More information may be located at: #1180 (comment).

NOTE: This fix should be released for both 4.x.x (currently on pub.dev) & 5.x.x (post #1158 i.e. next version).

This pull-request also resolves another issue for older Windows versions (builds lower than 17763), where Dart sided fallback implementation couldn't be registered correctly.

Related Issues

Closes #1180.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

…inux

* Now Share.shareXFiles correctly throws UnimplementedError on Linux & Windows builds lower than 17763, instead of causing a stack-overflow

* Addresses fluttercommunity#1180
@miquelbeltran
Copy link
Member

Thanks a lot @alexmercerind

NOTE: This fix should be released for both 4.x.x (currently on pub.dev) & 5.x.x (post #1158 i.e. next version).

I am not sure if this will be possible, so it will just be released with the upcoming major release, unfortunately.

@alexmercerind
Copy link
Contributor Author

I am not sure if this will be possible, so it will just be released with the upcoming major release, unfortunately.

Understandable. Since, current 4.x.x don't include shareXFiles implementation for Windows/Linux anyway, the error should be understandable to the developers.

@miquelbeltran
Copy link
Member

Is shareXFiles implemented on the Windows cpp implementation? I couldn't find it.

@alexmercerind
Copy link
Contributor Author

Is shareXFiles implemented on the Windows cpp implementation? I couldn't find it.

Yes!

} else if (method_call.method_name().compare(kShareFiles) == 0 ||
method_call.method_name().compare(kShareFilesWithResult) == 0) {

The platform implementation (MethodChannelShare) for shareXFiles calls shareFilesWithResult internally (see L148 below).
So, same implementation is used on all Windows, Android & iOS.

/// Summons the platform's share sheet to share multiple files.
@override
Future<ShareResult> shareXFiles(
List<XFile> files, {
String? subject,
String? text,
Rect? sharePositionOrigin,
}) {
final mimeTypes =
files.map((e) => e.mimeType ?? _mimeTypeForPath(e.path)).toList();
return shareFilesWithResult(
files.map((e) => e.path).toList(),
mimeTypes: mimeTypes,
subject: subject,
text: text,
sharePositionOrigin: sharePositionOrigin,
);
}

@miquelbeltran
Copy link
Member

Got it, thanks!

@miquelbeltran miquelbeltran added Hacktoberfest Issues taking part in Hacktoberfest hacktoberfest-accepted labels Oct 10, 2022
@miquelbeltran miquelbeltran merged commit 23029d1 into fluttercommunity:main Oct 10, 2022
@alexmercerind alexmercerind deleted the fix-1180 branch October 22, 2022 08:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Hacktoberfest Issues taking part in Hacktoberfest hacktoberfest-accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Using Share.shareXFiles on Windows results in a stack overflow

2 participants