我已经在 Flutter 中实现了 webView,但它没有打开我在服务器上的 php 网站,这是我做错了。
我是 Flutter 的新手,并尝试使用 webview 将我的网站网页集成到我的应用程序中,但没有成功。
Widget build(BuildContext context) {
// TODO: implement build
return WebviewScaffold(
appBar: AppBar(iconTheme:IconThemeData(color: Colors.white),title: Text("Intake Form",style:new TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),backgroundColor:Colors.indigoAccent,automaticallyImplyLeading: false),
url: url,
//url: "http://xxxxxxxx/",
withJavascript: true,
supportMultipleWindows: true,
withLocalStorage: true,
allowFileURLs: true,
enableAppScheme: true,
appCacheEnabled: true,
hidden: false,
scrollBar: true,
geolocationEnabled: false,
clearCookies: true,
// usesCleartextTraffic="true"
);
}
我希望输出为运行 webview 但抛出错误。
最佳答案
在 Flutter 项目的主目录中,您有三个主要文件夹:
- lib = your Dart code
- ios = generated structure for iOS platform
- android = generated structure for Android platform
我们对 android
感兴趣目录。
当你打开它时,你会看到“典型的 Android 应用结构”。
所以你必须做两件事:
res
中添加新文件进入目录:
my_flutter_project/android/app/src/main/res/
创建 xml
目录(在 res
中!)
在里面 xml
添加名称为:network_security_config.xml
的新文件和内容:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
network_security_config.xml
应该位于路径:
my_flutter_project/android/app/src/main/res/xml/network_security_config.xml
Here you can find more information about this file:
https://developer.android.com/training/articles/security-config
转到:
flutter_project/android/app/src/main/AndroidManifest.xml
AndroidManifest.xml
是 XML 文件,结构:
<manifest>
<application>
<activity>
...
</activity>
<meta-data >
</application>
</manifest>
所以对于 <application>
PROPERTIES 你必须添加 1 行:
android:networkSecurityConfig="@xml/network_security_config"
application
开始标记内):<application
SOMEWHERE HERE IS OK
>
不作为标签:
<application> <--- opening tag
HERE IS WRONG!!!!
<application/> <--- closing tag
关于flutter - 如何在 flutter 中修复 'net::ERR_CLEARTEXT_NOT_PERMITTED',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55592392/