Skip to content

fix(share_plus): reset stale share state and normalize path separators on Windows - #3966

Open
OmarAfifi-CSE wants to merge 2 commits into
fluttercommunity:mainfrom
OmarAfifi-CSE:fix/share-plus-windows-path-and-state
Open

fix(share_plus): reset stale share state and normalize path separators on Windows#3966
OmarAfifi-CSE wants to merge 2 commits into
fluttercommunity:mainfrom
OmarAfifi-CSE:fix/share-plus-windows-path-and-state

Conversation

@OmarAfifi-CSE

Copy link
Copy Markdown

Description

This PR resolves critical state leakage and file sharing issues in share_plus_windows:

  1. State Leak Across Consecutive Invocations:

    • Previous Behavior: The member variables share_text_, share_subject_, share_uri_, share_title_, paths_, and mime_types_ in SharePlusWindowsPlugin were only conditionally overwritten when the corresponding argument was present in the incoming method call. If a user previously shared text and subsequently initiated a file-only share (without text), the stale text from the previous share was retained and sent alongside the file. Similarly, sharing files previously would cause subsequent text-only shares to leak the previous files.
    • New Behavior: All share parameters and file vectors are explicitly reset (.reset() and .clear()) at the start of HandleMethodCall before parsing new arguments, ensuring every share request executes with a clean, isolated state as originally intended.
  2. WinRT Path Separator Rejection:

    • Previous Behavior: Dart paths originating from File.path, Directory.systemTemp, or standard path packages frequently contain POSIX-style forward slashes (/). Windows Runtime Windows.Storage.StorageFile.GetFileFromPathAsync strictly rejects forward slashes with HRESULT 0x80070057 (E_INVALIDARG: "The specified path is invalid"), preventing files from being appended to storage_items. This caused the Windows Share Broker dialog to fail with "Try that again. We couldn't show you all the ways you could share."
    • New Behavior: Path separators are normalized by replacing L'/' with L'\\' using std::replace prior to invoking GetFileFromPathAsync.
  3. Mandatory Title Fallback for File Shares:

    • Previous Behavior: Setting a non-empty title on DataPackagePropertySet is mandatory on Windows. When sharing files without explicit text, subject, or title, properties->put_Title received an empty string, which can cause the Share Broker flyout to fail.
    • New Behavior: Added a graceful fallback to extract and use the first file's basename as the dialog title when no custom title, subject, or text is supplied.

Related Issues

Fixes file sharing failures on Windows 10/11 when using temporary or normalized Dart file paths, and resolves state leakage between consecutive share operations.

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 plugin version in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant