[webview_flutter] Fix crash in iOS external native API#10959
[webview_flutter] Fix crash in iOS external native API#10959stuartmorgan-g wants to merge 2 commits intoflutter:mainfrom
Conversation
Fixes a crash if `FWFWebViewFlutterWKWebViewExternalAPI`'s `webView(forIdentifier:withPluginRegistry:)` is called with a registry that doesn't contain a published webview plugin value. This can happen if the wrong object is passed in (e.g., the FlutterAppDelegate in an app that has adopted UIScene). Fixes flutter/flutter#181865
There was a problem hiding this comment.
Code Review
This pull request addresses a crash in the iOS external native API by replacing a force-cast with a safe optional cast. This correctly handles cases where the webview plugin isn't found in the provided registry. The change is accompanied by a new unit test to verify the fix, along with corresponding updates to the changelog and package version. The implementation is sound, but I've noted a minor issue in the new test code that will cause a compilation error.
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
The registrar(forPlugin:) method for macOS in EmptyRegistry is declared to return a non-optional FlutterPluginRegistrar, but the implementation returns nil. This will cause a compilation error on macOS because the protocol requires a non-optional return value.
To resolve this, you can return the registrar property, which will satisfy the protocol requirement without altering the test's behavior.
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | |
| return nil | |
| } | |
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | |
| return registrar | |
| } |
Fixes a crash if
FWFWebViewFlutterWKWebViewExternalAPI'swebView(forIdentifier:withPluginRegistry:)is called with a registry that doesn't contain a published webview plugin value. This can happen if the wrong object is passed in (e.g., the FlutterAppDelegate in an app that has adopted UIScene).Fixes flutter/flutter#181865
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3