flutter - Flutter中没有连接时如何处理CachedNetworkImage的错误?
问题描述
当我的控制台中没有互联网连接并且我找不到处理它的方法时,我收到此错误:
Failed host lookup: 'via.placeholder.com' (OS Error: nodename nor servname provided, or not known, errno = 8)
When the exception was thrown, this was the stack
Image provider: CachedNetworkImageProvider("http://via.placeholder.com/350x150.", scale: 1.0)
Image key: CachedNetworkImageProvider("http://via.placeholder.com/350x150.", scale: 1.0): CachedNetworkImageProvider("http://via.placeholder.com/350x150.", scale: 1.0)
我缓存的图像代码:
class CachedImage extends StatelessWidget {
final String imageUrl;
final String id;
CachedImage({this.imageUrl, this.id});
@override
Widget build(BuildContext context) {
return Hero(
tag: id,
child: CachedNetworkImage(
fit: BoxFit.fill,
imageUrl: imageUrl,
placeholder: (context, url) => SizedBox(
height: 50,
width: 50,
child: FittedBox(fit: BoxFit.scaleDown, child: LoadingIndicator()),
),
errorWidget: (context, url, error) =>
Icon(Icons.error, color: kAccentColor),
),
);
}
}
我尝试使用 try/catch,但仍然出现错误。
解决方案
推荐阅读
- javascript - 从 Vue.js 中的组件更改父级的布局
- python - 如何在我的 Django 项目中设置唯一的邮件注册?
- android - 从 Firestore 加载标记的最佳方式
- c++ - BSTR 分配混乱
- php - 在 WooCommerce 简单产品的添加到购物车按钮中显示可用性
- c# - 页面重新加载时图像不断消失
- javascript - 我找不到在某个 PDO 实例中提交此复选框循环结果的方法
- pandas - 如何使用 Dask 正确迭代 for 循环?
- python-3.x - Kinesis GetRecords API 返回空 Records[] 数组
- ios - 根据 UIProgressView 状态同步描边填充动画?