我以此为例
https://medium.com/@segaud.kevin/facebook-oauth-login-flow-with-flutter-9adb717c9f2e
创建一个http服务器以将html提供给Webview(作为提供其引用的本地html文件和本地javascript文件的一种方式)。加载网络视图时,它将返回net :: ERR_CLEARTEXT_NOT_PERMITTED
void main() async {
HttpServer server = await HttpServer.bind("localhost", 8080);
server.listen((HttpRequest request) async {
request.response
..statusCode = 200
..headers.set("Content-Type", ContentType.html.mimeType)
..write("<html><h1>Hello</h1></html>");
});
...
class DemoFlutterWebView3 extends StatefulWidget {
_DemoFlutterWebViewState3 createState() => _DemoFlutterWebViewState3();
}
class _DemoFlutterWebViewState3 extends State<DemoFlutterWebView3> {
Widget build(BuildContext context) {
return WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: "http://localhost:8080/");
}
}
我注意到WebView showing ERR_CLEARTEXT_NOT_PERMITTED although site is HTTPS并将android:usesCleartextTraffic =“ true”添加到清单文件中(在这里猜测!),但是它什么也没做。
有什么主意为什么会出错或显示引用javascript文件的html文件的另一种方式?