解决Flutter不允许加载网络图片导致的错误

flutter中从网络中加载图片的大坑!!!加粗样式

flutter报错 : DioError [DioErrorType.DEFAULT]:Bad State : Insecure HTTP is not allowed by platform
原因是IOS和Android 9.0对网络请求做了一些限制,不能直接访问http域名的地址
解决:通过配置允许不加密的请求

找到项目中的

安卓设备的处理方式

android/src/main/AndroidManifest.xml
```xml
<application
        android:label="untitled"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        <!--以下两句是加的-->
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"
        >

在main/res目录中新建一个xml目录 在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>
        </trust-anchors>
    </base-config>
</network-security-config> 

IOS解决

ios/Runner/info.plist文件,找到最后面的</dict></dict>之前添加

<key>NSAppTransportSecurity</key>
	<dict>
	    <key>NSAllowsArbitraryLoads</key>
	    <true/>
	</dict>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值