Flutter get reference after navigation pop

933 views Asked by At

I would like to get a reference to the screen I am going to show.

With this code:

Navigator.of(context).pop()

I actually going back to the previous screen but I would like to access that reference to do some work.

How can I do that? With my iOS background working in Swift I would have done something like that:

var newScreen = Navigator.of(context).pop();
1

There are 1 answers

0
E.Benedos On BEST ANSWER

You cannot create a reference because when you pop the current "route" all the data will be disposed.

But you can return a pop result to the awaiting parent as explained by official docs.

Something like:

//When you will dispose the pushed page/route you can pass your result to pop method
Navigator.pop(context, 'This is my new page result');

//In the parent page you will await for the result
final result = await Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => MyPushedPage()),
  );
print(result) //--> This is my new page result