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.

オープン
#74 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
dart, flutter
領域
mobile-dev

調査の方向性

まず、BlurHashをネットワーク画像のプレースホルダーとして使用して報告されたランタイムエラーを再現し、次にパッケージの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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fluttercommunity/flutter_blurhash のほかの issue

fluttercommunity/flutter_blurhash の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。