loadHtmlString method

  1. @override
Future<void> loadHtmlString(
  1. String html, {
  2. String? baseUrl,
})

See WebViewController.loadHtmlString or WebViewPlatformController.loadHtmlString.

Limitations on Linux

baseUrl is not supported because the underlying browser does not support baseUrl.

Known bug (?)

The timing of when Future is resolved is different from Android/iOS. Immediately after this method is resolved, the new URL cannot yet be obtained with currentUrl.

TODO(Ino): Immediately reflect the new URL in currentUrl.

Implementation

@override
Future<void> loadHtmlString(
  String html, {
  String? baseUrl,
}) async {
  final int? webviewId = instanceManager.getInstanceId(this);
  if (webviewId == null) {
    throw 'Failed to get the webview instance';
  }
  final data = base64Encode(utf8.encode(html));
  final dataUri = "data:text/html;base64,$data";

  await (await LinuxWebViewPlugin.channel)
      .invokeMethod('loadUrl', <String, dynamic>{
    'webviewId': webviewId,
    'url': dataUri,
  });
}