中渲染本地HTML文件
我正在尝试使用WebView_flutter插件在应用中显示一些静态HTML。
body: WebView(
initialUrl: Uri.dataFromString(
htmlString,
mimeType: 'text/html',
encoding: Encoding('utf-8')
).toString(),
),
我遇到了关于无效字符错误的错误,我认为这是因为URI默认为ASCII。我试图将编码的字符设置为UTF-8,但我不知道该怎么做。Encoding('utf-8')
显然不对。
如何设置编码?
您可以像这样获得编码:
Encoding.getByName('utf-8')
另请参见如何在Flutter
flutter
的安全URL编码例如。
String url = 'http://example.org/';
String postDataKey = "requestParam="
String postData = 'hdfhghdf+fdfbjdfjjndf'
在获取请求的情况下:
Uri.encodeComponent(url+postDataKey+postData);
在邮政数据请求的情况下使用 Flutter_inappwebview library
var data = postDataKey + Uri.encodeComponent(postData);
webViewController.postUrl(url: Uri.parse(url), postData: utf8.encode(data));