getUrl method
- @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebView.getUrl', apiUrl: 'https://developer.android.com/reference/android/webkit/WebView#getUrl()'), IOSPlatform(apiName: 'WKWebView.url', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1415005-url'), MacOSPlatform(apiName: 'WKWebView.url', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1415005-url'), WebPlatform(note: "For a same-origin iframe it returns the current location. After the first document loads, it returns null when the browser's same-origin policy prevents reading a cross-origin location."), WindowsPlatform(apiName: 'ICoreWebView2.get_Source', apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#get_source'), LinuxPlatform(apiName: 'webkit_web_view_get_uri', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.get_uri.html')])
Gets the URL for the current page. This is not always the same as the URL passed to PlatformWebViewCreationParams.onLoadStart because although the load for that URL has begun, the current page may not have changed.
Officially Supported Platforms/Implementations:
- Android WebView (Official API - WebView.getUrl)
- iOS WKWebView (Official API - WKWebView.url)
- macOS WKWebView (Official API - WKWebView.url)
- Web <iframe> but requires same origin:
- For a same-origin iframe it returns the current location. After the first document loads, it returns null when the browser's same-origin policy prevents reading a cross-origin location.
- Windows WebView2 (Official API - ICoreWebView2.get_Source)
- Linux WPE WebKit (Official API - webkit_web_view_get_uri)
Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.
Implementation
@SupportedPlatforms(
platforms: [
AndroidPlatform(
apiName: 'WebView.getUrl',
apiUrl:
'https://developer.android.com/reference/android/webkit/WebView#getUrl()',
),
IOSPlatform(
apiName: 'WKWebView.url',
apiUrl:
'https://developer.apple.com/documentation/webkit/wkwebview/1415005-url',
),
MacOSPlatform(
apiName: 'WKWebView.url',
apiUrl:
'https://developer.apple.com/documentation/webkit/wkwebview/1415005-url',
),
WebPlatform(
note:
"For a same-origin iframe it returns the current location. After the first document loads, it returns null when the browser's same-origin policy prevents reading a cross-origin location.",
),
WindowsPlatform(
apiName: 'ICoreWebView2.get_Source',
apiUrl:
'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#get_source',
),
LinuxPlatform(
apiName: 'webkit_web_view_get_uri',
apiUrl:
'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.get_uri.html',
),
],
)
Future<WebUri?> getUrl() {
throw UnimplementedError(
'${PlatformInAppWebViewControllerMethod.getUrl.name} is not implemented on the current platform',
);
}