StateError: Bad state: Cannot clone a disposed image. The clone() method of a previously-disposed Image was called. Once an Image object has been disposed, it can no longer be used to create handles, as the underlying data may have been released.
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 领域
- mobile-dev
调研方向
首先,使用 BlurHash 作为网络图像的占位符来重现报告的运行时错误,然后检查 package 的 BlurHash 图像处理路径和生命周期。将其与 Image.network 的直接行为进行比较。完成的标准是网络图像占位符不再尝试克隆已释放的图像,同时现有的图像加载和错误行为保持不变。
由索引模型根据 Issue 内容生成。
描述
After adding flutter_blurhash to my project, I started seeing the following runtime error:
StateError: Bad state: Cannot clone a disposed image.
The clone() method of a previously-disposed Image was called. Once an Image object has been disposed, it can no longer be used to create handles, as the underlying data may have been released.
When using BlurHash with a network image, Flutter sometimes throws StateError: Bad state: Cannot clone a disposed image.
code example:
/// {@template image_loader}
/// ImageLoader widget.
/// {@endtemplate}
class ImageLoader extends StatefulWidget {
/// {@macro image_loader}
const ImageLoader({
required this.imgUrl,
this.blurHash,
this.isCupertinoStyle = true,
this.fit = BoxFit.cover,
this.onErrorWidget,
this.borderRadius,
this.backgroundColor,
this.height,
this.width,
this.blendMode,
this.color,
super.key,
});
final String? imgUrl;
final String? blurHash;
final bool isCupertinoStyle;
final BoxFit? fit;
final Widget? onErrorWidget;
final BorderRadius? borderRadius;
final Color? backgroundColor;
final double? height;
final double? width;
final BlendMode? blendMode;
final Color? color;
@override
State<ImageLoader> createState() => _ImageLoaderState();
}
class _ImageLoaderState extends State<ImageLoader> {
final int animationDuration = 800;
@override
Widget build(BuildContext context) => widget.imgUrl != null && widget.imgUrl!.isNotEmpty
? ColoredBox(
color: widget.backgroundColor ?? Colors.transparent,
child: ClipRRect(
borderRadius: widget.borderRadius ?? BorderRadius.circular(0),
child: widget.blurHash != null &&
widget.blurHash!.isNotEmpty &&
!widget.imgUrl!.contains('.png')
? BlurHash(
hash: widget.blurHash!,
decodingHeight: widget.height?.round() ?? 32,
decodingWidth: widget.width?.round() ?? 32,
color: Colors.white,
image: widget.imgUrl,
imageFit: widget.fit ?? BoxFit.cover,
curve: Curves.easeInOut,
duration: Duration(milliseconds: animationDuration),
)
: Image.network(
widget.imgUrl!,
fit: widget.fit,
height: widget.height,
width: widget.width,
color: widget.color,
colorBlendMode: widget.blendMode,
cacheHeight: widget.height?.round(),
cacheWidth: widget.width?.round(),
errorBuilder: (context, error, stackTrace) => widget.onErrorWidget ??
const Icon(Icons.hide_image_rounded),
),
),
)
: Image.asset('assets/placeholder.png', fit: widget.fit);
}
This error does not appear when using Image.network directly.
It only happens when BlurHash is used as a placeholder together with a network image.
- 主要语言
- Dart
- 星标
- 576
- 派生
- 80
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fluttercommunity/flutter_blurhash 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 30/100
fluttercommunity/flutter_blurhash#66 · 1 条评论 ·
-
CacheManager未关闭
难度 3/5 1-2 天 新手友好度 45/100
fluttercommunity/flutter_blurhash#61 · 4 个 reaction ·
-
难度 5/5 一周以上 新手友好度 30/100
fluttercommunity/flutter_blurhash#51 · 1 条评论 · 2 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 25/100
fluttercommunity/flutter_blurhash#50 · 4 条评论 · 3 个 reaction ·
查看 fluttercommunity/flutter_blurhash 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
OscillateLabsLLC/ovos-gui-visage#52 ·
维护者通常 1 天内回复
-
bug triage
难度 2/5 1-3 小时 新手友好度 66/100
fluttercommunity/plus_plugins#4018 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
VeryGoodOpenSource/vgv_ai_cli#150 · 1 个 reaction ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 75/100
PATILYASHH/XPENC#206 · 1 条评论 ·