loadData method
Future<void>
loadData({
- required String data,
- String mimeType = "text/html",
- String encoding = "utf8",
- Uri? baseUrl,
- @Deprecated('Use `historyUrl` instead') Uri? androidHistoryUrl,
- Uri? historyUrl,
- @Deprecated('Use `allowingReadAccessTo` instead') Uri? iosAllowingReadAccessTo,
- Uri? allowingReadAccessTo,
Loads the given data
into this WebView, using baseUrl
as the base URL for the content.
mimeType
argument specifies the format of the data. The default value is"text/html"
.encoding
argument specifies the encoding of the data. The default value is"utf8"
.historyUrl
is an Android-specific argument that represents the URL to use as the history entry. The default value isabout:blank
. If non-null, this must be a valid URL.allowingReadAccessTo
, used in combination withbaseUrl
(using thefile://
scheme), it represents the URL from which to read the web content. ThisbaseUrl
must be a file-based URL (using thefile://
scheme). Specify the same value as thebaseUrl
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.
Supported Platforms/Implementations:
- Android native WebView (Official API - WebView.loadDataWithBaseURL)
- iOS (Official API - WKWebView.loadHTMLString or Official API - WKWebView.load)
Implementation
Future<void> loadData(
{required String data,
String mimeType = "text/html",
String encoding = "utf8",
Uri? baseUrl,
@Deprecated('Use `historyUrl` instead')
Uri? androidHistoryUrl,
Uri? historyUrl,
@Deprecated('Use `allowingReadAccessTo` instead')
Uri? iosAllowingReadAccessTo,
Uri? allowingReadAccessTo}) async {
assert(iosAllowingReadAccessTo == null ||
iosAllowingReadAccessTo.isScheme("file"));
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('data', () => data);
args.putIfAbsent('mimeType', () => mimeType);
args.putIfAbsent('encoding', () => encoding);
args.putIfAbsent('baseUrl', () => baseUrl?.toString() ?? "about:blank");
args.putIfAbsent(
'historyUrl',
() =>
historyUrl?.toString() ??
androidHistoryUrl?.toString() ??
"about:blank");
args.putIfAbsent(
'allowingReadAccessTo',
() =>
allowingReadAccessTo?.toString() ??
iosAllowingReadAccessTo?.toString());
await _channel.invokeMethod('loadData', args);
}