loadUrl method
Future<void>
loadUrl({
- required URLRequest urlRequest,
- @Deprecated('Use `allowingReadAccessTo` instead') Uri? iosAllowingReadAccessTo,
- Uri? allowingReadAccessTo,
Loads the given urlRequest
.
allowingReadAccessTo
, used in combination withurlRequest
(using thefile://
scheme), it represents the URL from which to read the web content. This URL must be a file-based URL (using thefile://
scheme). Specify the same value as the URL parameter to prevent WebView from reading any other content. Specify a directory to give WebView permission to read additional files in the specified directory. NOTE: available only on iOS.
NOTE for Android: when loading an URL Request using "POST" method, headers are ignored.
Supported Platforms/Implementations:
- Android native WebView (Official API - WebView.loadUrl). If method is "POST", Official API - WebView.postUrl
- iOS (Official API - WKWebView.load. If
allowingReadAccessTo
is used, Official API - WKWebView.loadFileURL)
Implementation
Future<void> loadUrl(
{required URLRequest urlRequest,
@Deprecated('Use `allowingReadAccessTo` instead')
Uri? iosAllowingReadAccessTo,
Uri? allowingReadAccessTo}) async {
assert(urlRequest.url != null && urlRequest.url.toString().isNotEmpty);
assert(iosAllowingReadAccessTo == null ||
iosAllowingReadAccessTo.isScheme("file"));
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('urlRequest', () => urlRequest.toMap());
args.putIfAbsent(
'allowingReadAccessTo',
() =>
allowingReadAccessTo?.toString() ??
iosAllowingReadAccessTo?.toString());
await _channel.invokeMethod('loadUrl', args);
}