本文介绍了颤抖如何处理Image.network错误(例如404或错误的url)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当网址错误或目标指向404时,如何处理Image.network.

How to handle Image.network when the url is wrong or the destination leads to 404.

例如尝试

Image.network('https://image.tmdb.org/t/p/w92')

推荐答案

我建议使用 cached_network_image 这样就可以添加一个占位符图像,如果是404或403,还可以添加一个错误小部件.

I recommend using cached_network_image which gives an option to add a placeholder image and also an error widget in case of a 404 or 403.

CachedNetworkImage(
   imageUrl: "http://via.placeholder.com/350x150",
   placeholder: (context, url) => new CircularProgressIndicator(),
   errorWidget: (context, url, error) => new Icon(Icons.error),
),

这篇关于颤抖如何处理Image.network错误(例如404或错误的url)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:04