简体   繁体   中英

Flutter get reference after navigation pop

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();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM