Dispose widget when navigating to new route

后端 未结 2 758
离开以前
离开以前 2021-02-13 03:36

I have two screens in my app.

Screen A runs a computationally expensive operation while opened, and properly disposes by cancelling animations/subscriptions to the datab

2条回答
  •  情歌与酒
    2021-02-13 04:05

    I know it's a bit late but I think you should override the deactivate method. Since we are changing the page we are not actually destroying it, that's why the dispose isn't being called.

    If you'd like more information this page lists the lifecycle of the stateful widgets.

    From the link:

    'deactivate()' is called when State is removed from the tree, but it might be reinserted before the current frame change is finished. This method exists basically because State objects can be moved from one point in a tree to another.

提交回复
热议问题