Skip to content

[webview_flutter] unreliable encoding for web #104273

@FlafyDev

Description

@FlafyDev

The "data:text/html..." encoding that has to be done in the web version of webview_flutter isn't reliable enough.

2 examples of an issue caused by the current encoding
_controller.loadHtmlString("""
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<p>
  This is# an example page.
</p>
</body>
</html>
""");

Will only render "This is".

_controller.loadHtmlString("""
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#test {
  color: red;
}
</style>
</head>
<body>
<h1>Local demo page</h1>
<p class="test">
  This is an example page.
</p>
</body>
</html>
""");

Will not render anything.

My solution for fixing this is changing the encoding process to the one used by WebViewX.

So this: (the current encoding)

 _element.src =
  _element.src = Uri.dataFromString(
      'data:$contentType,${Uri.encodeFull(httpReq.responseText ?? '')}';

Will turn into this:

_element.src = Uri.dataFromString(
  httpReq.responseText ?? '',
  mimeType: contentType,
  encoding: Encoding.getByName('utf-8'),
).toString();

I'm currently working on a PR that does exactly that along with adding a few unimplemented features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: google_sign_inThe Google Sign-In pluginp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions