[Flutter]photo_viewパッケージを使っているプロジェクトで「Looking up a deactivated widget’s ancestor is unsafe」というエラーが出た場合の対処法(動画なし)

このページには広告が含まれる場合があります。

 

Flutterで画像をピンチイン・アウトで拡大・縮小できる大変便利な「photo_view」という有名なパッケージがありますが、

In action

このパッケージを使っているプロジェクトで画面遷移等を行った際に、

The following assertion was thrown while finalizing the widget tree:
Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

というエラーが出てしまう場合があります(アプリは落ちないが)。

これは、photo_viewパッケージのissueにも上がっていているのですが、現時点(2022/4)ではまだ解決されていないようなので、以下の次善の策を施してやる必要があるようです。

(pubspec.yamlファイルの「dependency_override」欄に以下を追記)

dependency_overrides:
  photo_view:
    git:
      url: https://github.com/bluefireteam/photo_view
      ref: master

こんな記事も読まれています

人気No.1

前向きな気持ちになれる 占星術・タロットリーディング

あすコロ式・相談サロン 【ナビるやん】

人に言えない悩みから使命・運勢診断まで、あなたに寄り添いながら“ナビゲート”する、あすコロ人気No.1のオンライン相談サロン。占星術・心理学・タロットの叡智を活かし、普段認識していない「潜在意識」にアクセスしてあなたの気づいていない可能性を拓かせ、明日から前向きに歩めるようになる60分のリーディングセッション。

今すぐ詳細を見る(メルマガ登録で初回半額) ▶

TOP