Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

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

Pre-Review Checklist

Footnotes

  1. 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

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
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 61 to 63
func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar {
return nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar {
return nil
}
func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar {
return registrar
}

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webview_flutter] Crash on startup after UISceneDelegate migration when registering Webview with Google Mobile Ads SDK

1 participant