loadData method

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebView.loadDataWithBaseURL', apiUrl: 'https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)'), IOSPlatform(apiName: 'WKWebView.loadHTMLString', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring', note: 'or [Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1415011-load)'), MacOSPlatform(apiName: 'WKWebView.loadHTMLString', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring', note: 'or [Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1415011-load)'), WebPlatform(), WindowsPlatform(apiName: 'ICoreWebView2.NavigateToString', apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#navigatetostring'), LinuxPlatform(apiName: 'webkit_web_view_load_html', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.load_html.html')])
Future<void> loadData({
  1. required String data,
  2. @SupportedPlatforms.new(platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform(), WebPlatform()]) String mimeType = "text/html",
  3. @SupportedPlatforms.new(platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) String encoding = "utf8",
  4. @SupportedPlatforms.new(platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) WebUri? baseUrl,
  5. @Deprecated('Use historyUrl instead') Uri? androidHistoryUrl,
  6. @SupportedPlatforms.new(platforms: [AndroidPlatform()]) WebUri? historyUrl,
  7. @Deprecated('Use allowingReadAccessTo instead') Uri? iosAllowingReadAccessTo,
  8. @SupportedPlatforms.new(platforms: [IOSPlatform(), MacOSPlatform()]) WebUri? 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 represents the URL to use as the history entry. The default value is about:blank. If non-null, this must be a valid URL.
  • allowingReadAccessTo, used in combination with baseUrl (using the file:// scheme), it represents the URL from which to read the web content. This baseUrl must be a file-based URL (using the file:// scheme). Specify the same value as the baseUrl parameter to prevent WebView from reading any other content. Specify a directory to give WebView permission to read additional files in the specified directory.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • data: all platforms
  • mimeType:
    • Android WebView
    • iOS WKWebView
    • macOS WKWebView
    • Web <iframe> but requires same origin
  • encoding:
    • Android WebView
    • iOS WKWebView
    • macOS WKWebView
  • baseUrl:
    • Android WebView
    • iOS WKWebView
    • macOS WKWebView
  • historyUrl:
    • Android WebView
  • allowingReadAccessTo:
    • iOS WKWebView
    • macOS WKWebView

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'WebView.loadDataWithBaseURL',
      apiUrl:
          'https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)',
    ),
    IOSPlatform(
      apiName: 'WKWebView.loadHTMLString',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring',
      note:
          'or [Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1415011-load)',
    ),
    MacOSPlatform(
      apiName: 'WKWebView.loadHTMLString',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring',
      note:
          'or [Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1415011-load)',
    ),
    WebPlatform(),
    WindowsPlatform(
      apiName: 'ICoreWebView2.NavigateToString',
      apiUrl:
          'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#navigatetostring',
    ),
    LinuxPlatform(
      apiName: 'webkit_web_view_load_html',
      apiUrl:
          'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.load_html.html',
    ),
  ],
)
Future<void> loadData({
  required String data,
  @SupportedPlatforms(
    platforms: [
      AndroidPlatform(),
      IOSPlatform(),
      MacOSPlatform(),
      WebPlatform(),
    ],
  )
  String mimeType = "text/html",
  @SupportedPlatforms(
    platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()],
  )
  String encoding = "utf8",
  @SupportedPlatforms(
    platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()],
  )
  WebUri? baseUrl,
  @Deprecated('Use historyUrl instead') Uri? androidHistoryUrl,
  @SupportedPlatforms(platforms: [AndroidPlatform()]) WebUri? historyUrl,
  @Deprecated('Use allowingReadAccessTo instead')
  Uri? iosAllowingReadAccessTo,
  @SupportedPlatforms(platforms: [IOSPlatform(), MacOSPlatform()])
  WebUri? allowingReadAccessTo,
}) {
  throw UnimplementedError(
    '${PlatformInAppWebViewControllerMethod.loadData.name} is not implemented on the current platform',
  );
}