首页 > 其他分享 >flutter加载网络图片错误EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE The following SocketException was thrown r

flutter加载网络图片错误EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE The following SocketException was thrown r

时间:2024-03-28 20:22:18浏览次数:28  
标签:SocketException EXCEPTION associated image 网络 图片 加载

在flutter里使用image.network加载网络图片遇到错误══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════The following SocketException was thrown resolving an image codec: Failed host lookup: 'www.xxx.com' (OS Error: No address associated with hostname, errno = 7


 

图片加载不出来,刚开始以为是url的问题,结果在浏览器上直接访问网络地址是可以看到图片的,后来看了别人的博客才知道原来是没有配置网络权限的问题

 

 

解决方法:配置网络权限

  1. 用vscode打开项目的话:在项目中的android/src/main/AndroidManifest.xml中添加下列代码:
     <!-- 配置网络权限 -->
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

 

 

注意配置网络权限的位置: 跟<application>是同一级


 

  1. 第二步:在模拟器里要打开网络(移动数据),然后再shift+R热加载一下项目就可以加载到图片了

     

标签:SocketException,EXCEPTION,associated,image,网络,图片,加载
From: https://www.cnblogs.com/wu555dt/p/18102545

相关文章