flutterfirebase-admob

When the dispose() method should be executed?


When the dispose() method should be executed?

For instance, there are two widgets:

The widget 1 has the dispose() method, because this widget intialize admob add, so we should implement there dispose with

_bannerAd?.dispose();

Now, let's imagine a situation. I go from W1 to W2 and then back to W1. Should not the dispose() has to be executed? I have modeled such navigation and the dispose() was not execured.

Then I press back button on emulator (to return to the W2) and now the dispose was executed(!), why it was executed in this case and was not when we made navigator push the widget 2?

enter image description here


Solution

  • it is because, .pop() will remove the route from stack where .push() will not, removing from stack essentially means disposing. (pop happens when you come back W2)