dispose method not getting called

Viewed 930

In my main page, I have two tabs, named tab 1 and tab 2. When switch to tab 2, it has an icon on upper right corner.When icon is clicked, it will open page C.

I notice when I switch from tab 1 to tab2, it will call dispose in tab 1. When I switch from tab 2 to tab 1, tab2 dispose will be called.

However when I click the icon in tab 2 to navigate to page c, dispose in tab 2 is not getting called. How can I make dispose method called when I click the icon to navigate to page C?

1 Answers

You're using the Navigator.pushNamed method to push page C on top. This creates a stack of pages, so the tabbed pages are not disposed, they're still there just not visibly. Use Navigator.pushReplacementNamed instead to replace the current page and take the old one off the stack and dispose it.

Related