fix(share_plus): fail with a PlatformException instead of crashing when there is no implicit view - #3996
Open
TanimowoObaloluwaDavid wants to merge 1 commit into
Conversation
…en there is no implicit view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
share()on Windows terminates the process when the plugin is registered without an implicit view, as happens for apps built on a bareFlutterEngine(experimental windowing,enable-windowing: true).GetWindow()dereferenced the result ofregistrar_->GetView()unconditionally:PluginRegistrarWindows::GetView()returnsnullptrunless the embedder created an implicit view, which is the deprecated accessor for exactly the reason that no single implicit view exists once multi-window is in play. So the null dereference happens before any Dart-side error can be raised: no exception, no log line, the process is just gone.This PR makes
GetWindow()null-safe and turns the crash into a catchablePlatformException(no_implicit_view) from thesharehandler, so apps can handle or surface the failure instead of dying.Anchoring the dialog to a specific window would need
GetViewById(), and the plugin has no way to be told which window to use, so that is deliberately left out of scope.Related Issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Notes on verification: this change is Windows-only C++, so it is not covered by the Dart unit tests and I could not compile it locally (no Visual Studio toolchain available in my environment). Windows CI is the compile check. I have not been able to exercise the multi-window path at runtime.
Breaking Change
FlutterEnginenow get aPlatformExceptiononshare()instead of a silent process kill. No API or pubspec change.