如果CachedNetworkImageProvider由于某种原因无法获取远程图像,我想显示默认的本地图像:
Container(
width: 80.0,
height: 120.0,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new CachedNetworkImageProvider(url),
),
),
),
您可以使用带有cached network image参数的errorWidget
插件,安装步骤在链接中说明。这是它的一个示例实现:
image: new CachedNetworkImage(
imageUrl: "http://via.placeholder.com/350x150",
placeholder: new CircularProgressIndicator(),
errorWidget: new Image.assets('error.jpg'), // This is what you need
fit: BoxFit.fill,
fadeInCurve: Curves.easeIn ,
fadeInDuration: Duration(seconds: 2),
fadeOutCurve: Curves.easeOut,
fadeOutDuration: Duration(seconds: 2),
),
你可以注意到它还有其他功能,如placeholder
和动画,所以你将有更多的功能来修补。