image - 在 Flutter 中使用缓存网络图像的原生“AssertionError_throwNew”
问题描述
当我决定将缓存的图像放在网络图像的位置时,我正在开发我的应用程序,因为效果更好。我做到了。但是我的图像不再可以点击了。当我点击全屏时,图像只有白色,并显示你们在“errors_patch.dart”的标题(原生“AssertionError_throwNew”;)上看到的错误。我敢打赌是因为缓存的网络图像与 PhotoView idk 内的 imageProvider 中的仅网络图像混合。在此先感谢,这是我的代码(为了帮助您更多,我将容器也放在图像所在的位置):
final urlImages1 = [
'https://i.imgur.com/Y3UejT0.jpg',
'https://i.imgur.com/KNFL3qd.jpg',
'https://i.imgur.com/fxAH9HY.jpg',
'https://i.imgur.com/9GkgdKx.jpg',
];
Widget buildImage(String urlImage01, int index) => Container(
margin: EdgeInsets.symmetric(horizontal: 5),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: GestureDetector(
child: Hero(
tag: 'imageHero',
child: CachedNetworkImage(
imageUrl: urlImage01,
imageBuilder: (context, imageProvider) => Container(
width: 350,
height: 405,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover),
),
),
placeholder: (context, url) => SizedBox(
width: 100,
height: 100,
child: Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(Colors.pink.shade700),
)),
),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
leading: backIcon(),
),
body: GestureDetector(
child: Center(
child: Hero(
tag: 'imageHero',
child: PhotoView(
backgroundDecoration:
BoxDecoration(color: Colors.black87),
minScale: PhotoViewComputedScale.contained * 0.9,
maxScale: PhotoViewComputedScale.covered * 2,
imageProvider: NetworkImage(
urlImage01,
),
),
),
),
),
);
},
),
);
},
),
),
);
Container(
width: 405,
child: ClipRRect(
borderRadius:
BorderRadius.only(
topLeft:
Radius.circular(20),
topRight:
Radius.circular(20),
),
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
children: [
CarouselSlider.builder(
itemCount:
urlImages1.length,
itemBuilder: (context,
index, realIndex) {
final urlImage01 =
urlImages1[index];
return buildImage(
urlImage01,
index);
},
options:
CarouselOptions(
height: 300,
enlargeStrategy:
CenterPageEnlargeStrategy
.height,
enlargeCenterPage:
true,
onPageChanged: (index,
reason) =>
setState(() =>
currentIndex =
index),
),
),
SizedBox(
height: 10,
),
],
),
),
),
解决方案
更新,伙计们,我是对的。这真的是我认为是错误的地方。所以只要改变这个粒子:
child: PhotoView(
backgroundDecoration:
BoxDecoration(color: Colors.black87),
minScale: PhotoViewComputedScale.contained * 0.9,
maxScale: PhotoViewComputedScale.covered * 2,
imageProvider: NetworkImage(
urlImage01,
),
),
对此:
child: PhotoView(
backgroundDecoration:
BoxDecoration(color: Colors.black87),
minScale: PhotoViewComputedScale.contained * 0.9,
maxScale: PhotoViewComputedScale.covered * 2,
imageProvider: CachedNetworkImageProvider(
urlImage01,
),
),
我做到了。所以不用担心。问题是我无法将此答案标记为已解决。仅在 2 天内
推荐阅读
- react-native - 附件和操作的 Getstream 聊天文档 / 如何制作可点击的预定义答案?
- windows - 如何使用powershell同时为目录中的所有.exe文件创建多个快捷方式
- android - Android,循环如何工作?(科特林)
- angularjs - 如何使用选项卡移出羽毛笔编辑器
- python - 如何按 pandas.value_counts 对结果进行排序
- json - jq 获取对象键并在一个过滤器中更改其名称
- amazon-web-services - 将 Cloudwatch 日志流式传输到 Amazon ES
- spark-java - 在java spark中返回没有内容类型标头的空正文
- php - 未捕获的 PDOException:找不到驱动程序 ... Window XAMPP MySQL PHP 版本 => 7.4.4
- django - Django模板中'form.as_p'中的值'form'从何而来?