koraxis
koraxis

Reputation: 811

Flutter screen change callback

I want to get a callback when the screen is changed, so I can stop my recurring request that runs on that specific screen. “dispose” is only called when Navigator.pop is used, but not when Navigator.push is called. Is there a way to detect that the screen is changed and not being shown at the moment?

Upvotes: 6

Views: 7216

Answers (1)

tuan vu
tuan vu

Reputation: 353

Register a RouteObserver on your MaterialApp or WidgetsApp and make your stateful widget a RouteAware. Sample code here: RouteObserver

Upvotes: 10

Related Questions