【发布时间】:2021-07-14 17:40:59
【问题描述】:
我正在使用cached_network_image 包来显示图像并在加载时使用占位符。以下是我遇到的错误以及我使用CachedNetworkImage 的小部件。
The argument type 'CachedNetworkImage' can't be assigned to the parameter type 'ImageProvider<Object>'
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
image: DecorationImage(
image: CachedNetworkImage(
imageUrl: "https://cdn....${item.id}/${item.imageName}.jpg",
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
fit: BoxFit.cover,
),
),
搜索了一下,我在这个 Github 线程中发现了类似的问题,并且一个答案解释了 CachedNetworkImage 提供了一个回调,我可以使用它来返回图像提供程序。我试过那个例子,但仍然有这个错误。
https://github.com/Baseflow/flutter_cached_network_image/issues/177#issuecomment-510359079
我注意到 Github 线程中的问题有 The argument type 'CachedNetworkImage' can't be assigned to the parameter type 'ImageProvider'. 错误,而我的是 The argument type 'CachedNetworkImage' can't be assigned to the parameter type 'ImageProvider<Object>'.
谁能告诉我我做错了什么。
【问题讨论】:
-
CNI(...,child:Container)
-
图片加载后会渲染小部件
标签: flutter