Skip to content

feat(share_plus): implement previewThumbnail preview on Android and Windows#3913

Open
diablodale wants to merge 6 commits into
fluttercommunity:mainfrom
diablodale:share_preview_img
Open

feat(share_plus): implement previewThumbnail preview on Android and Windows#3913
diablodale wants to merge 6 commits into
fluttercommunity:mainfrom
diablodale:share_preview_img

Conversation

@diablodale

Copy link
Copy Markdown

Description

Implements ShareParams.previewThumbnail end-to-end on Android and Windows. Previously it was an unimplemented stub, the value was accepted by the API but never sent over the method channel or used natively, so setting it did nothing.

  • Android: attaches the thumbnail to the chooser intent via ClipData, so the system Sharesheet (API 29+) shows
    a rich preview for text/URI shares. Ignored for file shares (the system previews those itself).
  • Windows: sets the thumbnail as DataPackage.Thumbnail in the share UI.

Verified

  • Android physical device (Pixel, API 37) and emulators (API 28 and 33), confirming the preview renders, Direct Share
    suggestions are preserved, and the pre-API-29 path is cleanly skipped
  • Windows the thumbnail is handed to the OS correctly (put_Thumbnail returns S_OK), though note the redesigned
    Windows 11 share sheet does not display the content preview for text shares, so it may not be visible there despite
    being set.

Related Issues

Related #1221

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.

previewThumbnail was declared on ShareParams but never serialized across
the method channel nor used by any native implementation, so setting it
had no effect.

- Serialize previewThumbnail to a file path in MethodChannelShare, reusing
  the existing _getFile helper so in-memory XFiles are materialized.
- Android: attach the thumbnail to the chooser intent via data + ClipData
  with FLAG_GRANT_READ_URI_PERMISSION on text/URL shares (API 29+), and
  grant read access to resolved activities. File shares keep their own
  EXTRA_STREAM-derived preview.
- Windows: set DataPackage.Thumbnail from the thumbnail file via
  RandomAccessStreamReference in the DataRequested callback.
- Update docs to list Android and Windows as supported platforms and add
  a serialization test.
setData() clears the intent type (text/plain), which removes Direct Share
(recommended people) suggestions. Attach the preview thumbnail via ClipData
only, preserving the MIME type.
melos run format caused changes throughout the monorepo.
This commit includes only those formatting changes
within the share_plus folder.
@diablodale

Copy link
Copy Markdown
Author

CI is compiling differently that local. It is unclear your compiler, switches, etc. When flutter does local build this failure (looks like a warning that has been promoted to error) does not exist. This is a core flutter generated file and I do not recommend changing it.

ERROR: D:\a\plus_plugins\plus_plugins\packages\share_plus\share_plus\example\windows\runner\win32_window.cpp(179,3): error C2360: initialization of 'rect' is skipped by 'case' label [D:\a\plus_plugins\plus_plugins\packages\share_plus\share_plus\example\build\windows\x64\runner\example.vcxproj]

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