shouldOverrideUrlLoading method
Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
navigationAction represents an object that contains information about an action that causes navigation to occur.
NOTE: In order to be able to listen this event, check the InAppWebViewSettings.useShouldOverrideUrlLoading setting documentation.
Officially Supported Platforms/Implementations:
- Android WebView (Official API - WebViewClient.shouldOverrideUrlLoading):
- There isn't any way to load an URL for a frame that is not the main frame, so if the request is not for the main frame, the navigation is allowed by default. However, if you want to cancel requests for subframes, you can use the
InAppWebViewSettings.regexToCancelSubFramesLoadingsetting to write a Regular Expression that, if the url request of a subframe matches, then the request of that subframe is canceled. Instead, theInAppWebViewSettings.regexToAllowSyncUrlLoadingsetting could be used to allow navigation requests synchronously, as this event is synchronous on native side and the current plugin implementation will always cancel the current request and load a new request if this event returnsNavigationActionPolicy.ALLOWbecause Flutter method channels work only asynchronously. Also, this event is not called for POST requests and is not called on the first page load.
- There isn't any way to load an URL for a frame that is not the main frame, so if the request is not for the main frame, the navigation is allowed by default. However, if you want to cancel requests for subframes, you can use the
- iOS WKWebView (Official API - WKNavigationDelegate.webView)
- macOS WKWebView (Official API - WKNavigationDelegate.webView)
- Windows WebView2
Parameters - Officially Supported Platforms/Implementations:
navigationAction: all platforms
Use the PlatformInAppBrowserEvents.isMethodSupported method to check if this method is supported at runtime.
Implementation
@override
Future<NavigationActionPolicy> shouldOverrideUrlLoading(
navigationAction) async {
return NavigationActionPolicy.ALLOW;
}