Keerti Purswani
Keerti Purswani

Reputation: 5381

Which function is called when a screen is opened after popping from navigation stack?

I have 2 screens - screen A and screen B. I navigate from screen A to screen B. I want to take some particular action when I am coming BACK to screen A by popping out screen B from the navigation stack. I know I can use didUpdateWidge but I can't figure out an efficient way of doing it. Is using Inherited Widget the correct way here?

Upvotes: 0

Views: 114

Answers (2)

Richard Heap
Richard Heap

Reputation: 51751

Navigator.push[Named] returns a Future that completes when screen B pops. So add the code you want to execute after the pop to then.

  Navigator.pushNamed(context, '/someRoute').then((_) {/* do stuff here */});

Upvotes: 1

Bohdan Uhrynovskiy
Bohdan Uhrynovskiy

Reputation: 366

Try to use WillPopScope. This widget allows to catch back button press.

Upvotes: 0

Related Questions