CarGuo/gsy_flutter_demo

列表滑动停靠效果2进入页面再出来会报错

shexm opened this issue · 1 comments

shexm commented

列表滑动停靠效果2(sliver_stick_demo_page)进入页面再出来好像会报
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.
大佬能不能帮我解释一下为什么,还有页面几个Future.delayed的用法,为什么不用就会报错

Future.delayed 是因为没有执行完 build ,Element 还没正式加入,不就是作为 Element 的抽象对象 context 还不能直接使用, Future.delayed 或者直接用 Future() ,只是让执行在下个任务周期去使用 context ,那时候context就已经准备好了,也可以使用 SchedulerBinding