简体   繁体   English

如何在 flutter 中显示来自 API 响应的图像

[英]How to display image which comes from API response in flutter

I'm trying to display the image which i get from api response.我正在尝试显示从 api 响应中获得的图像。

here my api response look like这里我的 api 回复看起来像

{
            "id": 40,
            "user_id": 49,
            "contact_person": "fss",
            "relation": "dfs",
            "phone": "dsf",
            "image": "emergency/1735859198927595.jpg",
            "created_at": "2022-06-17T05:38:54.000000Z",
            "updated_at": "2022-06-17T05:38:54.000000Z"
        },

and displaying it on listtile leading like this并将其显示在像这样的listtile leading

ListTile(leading: SizedBox(height: 50,width: 50,
         child: Image.network(emergencyContact[index].image))

but it gives me this error但它给了我这个错误

Exception caught by image resource service ════════════════════════════
Invalid argument(s): No host specified in URI file:///emergency/1735859198927595.jpg

please help how to fix this issue.请帮忙解决这个问题。

your image url is not.network url, it should start with https or http other wise it will not work你的图像 url 不是.network url,它应该以httpshttp开头,否则它将不起作用

String url = https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png;

ListTile(leading: SizedBox(height: 50,width: 50,
     child: Image.network(url))

So the Exception Error explains very well that you did not provide your host: https://your.site.com/image-path.png所以异常错误很好地解释了你没有提供你的主机: https://your.site.com/image-path.png

Please append https://your.site.com/${emergencyContact[index].image}请 append https://your.site.com/${emergencyContact[index].image}

ListTile(leading: SizedBox(height: 50,width: 50,
         child: Image.network(`https://your.site.com/${emergencyContact[index].image}`))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM