[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

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

イチオシ

40代から感じるモヤモヤを解消できる 無料動画セミナー

あすコロ式・40代からの人生アップデート【新】戦略

アラフォーでキャリアを失ったバリバリ左脳人間・スピリチュアル耐性ゼロの元金融マンが、人生どん底から立ち上がる過程でたどり着いた「人生再構築メソッド」。40代・50代を過ぎて多くの人が感じる「このままでいいんかな?」「この先どうしたらいいかわからない」というモヤモヤを解消し、人生後半戦をアップデートさせる【新】戦略。

今すぐ無料で動画セミナー(80分)を見る ▶

TOP