shouldOverrideUrlLoading property

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebViewClient.shouldOverrideUrlLoading', apiUrl: 'https://developer.android.com/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)', note: """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.regexToCancelSubFramesLoading] setting to write a Regular Expression that, if the url request of a subframe matches, then the request of that subframe is canceled. Instead, the [InAppWebViewSettings.regexToAllowSyncUrlLoading] setting could be used to allow navigation requests synchronously. On Android Forge, HTTP/HTTPS main-frame navigations continue through WebView when this event returns [NavigationActionPolicy.ALLOW], preserving the original browsing context. Returning [NavigationActionPolicy.CANCEL] attempts to stop that in-flight navigation; non-HTTP(S) URLs are reloaded after an [ALLOW] because Flutter method channels work asynchronously. Also, this event is not called for POST requests and is not called on the first page load."""), IOSPlatform(apiName: 'WKNavigationDelegate.webView', apiUrl: 'https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455641-webview'), MacOSPlatform(apiName: 'WKNavigationDelegate.webView', apiUrl: 'https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455641-webview'), WindowsPlatform(), LinuxPlatform(apiName: 'WebKitWebView::decide-policy', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/signal.WebView.decide-policy.html')])
FutureOr<NavigationActionPolicy?> Function(T controller, NavigationAction navigationAction)? shouldOverrideUrlLoading
final

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:

Parameters - Officially Supported Platforms/Implementations:

  • navigationAction: all platforms

Use the PlatformWebViewCreationParams.isPropertySupported method to check if this property is supported at runtime.

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'WebViewClient.shouldOverrideUrlLoading',
      apiUrl:
          'https://developer.android.com/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)',
      note:
          """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.regexToCancelSubFramesLoading] setting
to write a Regular Expression that, if the url request of a subframe matches, then the request of that subframe is canceled.
Instead, the [InAppWebViewSettings.regexToAllowSyncUrlLoading] setting could
be used to allow navigation requests synchronously. On Android Forge, HTTP/HTTPS main-frame
navigations continue through WebView when this event returns [NavigationActionPolicy.ALLOW],
preserving the original browsing context. Returning [NavigationActionPolicy.CANCEL] attempts to
stop that in-flight navigation; non-HTTP(S) URLs are reloaded after an [ALLOW] because Flutter
method channels work asynchronously.
Also, this event is not called for POST requests and is not called on the first page load.""",
    ),
    IOSPlatform(
      apiName: 'WKNavigationDelegate.webView',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455641-webview',
    ),
    MacOSPlatform(
      apiName: 'WKNavigationDelegate.webView',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455641-webview',
    ),
    WindowsPlatform(),
    LinuxPlatform(
      apiName: 'WebKitWebView::decide-policy',
      apiUrl:
          'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/signal.WebView.decide-policy.html',
    ),
  ],
)
final FutureOr<NavigationActionPolicy?> Function(
  T controller,
  NavigationAction navigationAction,
)?
shouldOverrideUrlLoading;