解决办法:data:text/html;charset=utf-8;base64,${base64Encode(const Utf8Encoder().convert(_html))}
主要是添加charset=utf-8
_renderHtml (html) {
String _html = '''
<html>
<head>
<meta charset="UTF-8">
</head>
<body onload="SendHight()">
${html}
<script type="text/javascript">window.extents.postMessage(document.body.offsetHeight);</script>
</body>
</html>
''';
String _S="data:text/html;charset=utf-8;base64,${base64Encode(const Utf8Encoder().convert(_html))}";
return _S;
}
调用方法
Container(
height: _htmlHeight,
child: WebView(
initialUrl: _renderHtml(widget.item.content),
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
},
javascriptChannels: <JavascriptChannel>[
_SetHtmlHeight(context)
].toSet(),
),
)
网友评论