flutter - Flutter BlurhHash 通过 CachedNetworkImage 加载时闪烁
问题描述
我正在尝试将 BlurHash 与 CachedNetworkImage 结合起来,以便在从 Cloud Firestore 加载图像时提供良好的过渡。
问题在于,在过渡到加载的图像开始之前,大多数时间 BlurHash 会闪烁。
我将其范围缩小到它闪烁从模型对象加载的哈希值,从 Firestore 返回。如果我对模糊哈希进行硬编码,则不会发生闪烁。
Widget get _networkImage {
final Duration fadeDuration = Duration(milliseconds: hasBlurhHash ? 500 : 0);
return CachedNetworkImage(
imageUrl: imageURL!,
fit: fit,
width: width,
height: height,
fadeInDuration: fadeDuration,
fadeOutDuration: fadeDuration,
placeholder: (context, __) => hasBlurhHash ? _blurHash : _loader(context),
errorWidget: (context, url, error) => Image(image: AssetImage("assets/img/aboutus.png")),
);
}
Widget get _blurHash => BlurHash(hash: blurHash!, color: Colors.white);
Widget _loader(BuildContext context) => ConstrainedBox(
constraints: BoxConstraints(maxHeight: 48.h, maxWidth: 48.h),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryColor),
strokeWidth: 4,
),
),
);
问题是 blurHash 数据没有改变,所以我不确定它为什么会发生和/或如何解决它。
有人有任何线索吗?
解决方案
推荐阅读
- python - 两个 Pandas Series 的字符串匹配
- c# - Entity Framework Core - 在 Queryable 中使用扩展方法
- powershell - 如何将十进制转换为十六进制变量?
- macos - 在 Mac 上卸载使用 curl 安装的 windows VM
- javascript - TypeError:this.splice 不是函数
- php - 如何在 Dreamhost 中使用 php 设置 cron?
- curl - aiohttp 上传文件为 curl -F
- javascript - 如何使用 Vue js 创建收藏夹列表。允许用户选择最多 5 个选项
- operating-system - 如何在根级别的 FreeBSD 内核中生成随机数?
- javascript - reactjs中如何根据hash对组件的顺序进行排序/隐藏?