我正在为所有国家/地区创建滚动视图,每个国家/地区都有一个标志作为图像和一个名称,我基于的数据是从 API 更新的,在 API 响应后,我将国家数据设置为该州对象,我调用 this.setSatet(newstate) 来更新滚动视图。
所以,我使用这段代码来显示每个国家的国旗:
{
this.state.data_countries.map((country, index) => (
<View key={country._id} style={styles.item}>
<Image
source={{
uri: country.countryInfo.flag,
}}
style={{
maxWidth: 40,
maxHeight: 30,
flex: 1,
}}
onError={this.test_error}
></Image>
<Text
style={{
textAlign: "center",
flex: 1,
}}
>
{country.country}
</Text>
</View>
));
}
我确保给定的URI是正确的,我已将以下所有网络安全添加到我的 android 项目中:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<!-- THIS FOR THE DOMAIN OF MY IMAGES SOURCE example : https://disease.sh/assets/img/flags/us.png-->
<domain includeSubdomains="true">disease.sh</domain>
<!-- THIS FOR THE DOMAIN OF MY API -->
<domain includeSubdomains="true">nepalcorona.info</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
我在模拟器上测试了我的应用程序,它运行良好,但在我的真实设备上无法运行我得到的图像没有显示一个空的图像视图,请有任何想法的人可以帮助我,请分享。我有很多时间寻找解决方案,但没有办法,请帮忙。