The following assertion was thrown while finalizing the widget treeLooking up a deactivated widgets ancestor is unsafeAt this point the state of the widgets element tree is no longer stableTo safely r
这个错误提示是在widget tree被销毁的时候出现的,意味着在dispose()方法中引用了已经被销毁的widget的祖先节点,这是不安全的行为。
解决方法是在didChangeDependencies()方法中调用dependOnInheritedWidgetOfExactType()方法保存对祖先节点的引用,然后在dispose()方法中使用这个引用来访问祖先节点。这样可以确保在widget tree被销毁时仍然可以安全地访问祖先节点。
原文地址: https://www.cveoy.top/t/topic/dfpu 著作权归作者所有。请勿转载和采集!