在做flutter webview嵌入頁面請求時,發現調用請求後,頁面不能加載,但是把請求的url改成的百度的鏈接,就可用,所以,判斷是調用http和https的問題。估計是高版本訪問權限的問題。插件用的是 webview_flutter: ^0.3.21
看下怎麼解決:
1、iOS添加信任
webview_flutter 在使用過程中會iOS出現無法加載HTTP請求的情況, 但是Flutter 卻可以加載HTTP請求。這就與兩個的框架有關了,Flutter是獨立於UIKit框架的。
解決方案就是在iOS 的info.plist中添加對HTTP的信任。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2、android添加信任
安卓端 9.0之前的系統,使用過程中並未發生異常。 9.0之後,也不支持HTTP,同樣也得添加信任
第一步:在清單文件AndroidManifest.xml的application標籤裏面設置networkSecurityConfig屬性如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config">
<!-- ... -->
</application>
</manifest>
第二步:在資源文件夾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" />
</trust-anchors>
</base-config>
</network-security-config>
結束