Reputation: 217
I currently have the route
Navigator.pop(context,"/second");
However, I need to pass the argument contact
. I know this works fine with arguments:
for popAndPushNamed
, but I'm not sure how to do it for pop/popUntil
etc.
Contact contact = ModalRoute.of(context).settings.arguments;
The code is on an edit page. On the onPress
, it directs back to the previous page showing the updated document fields.
Upvotes: 6
Views: 13877
Reputation: 14435
Navigator.pop(context, "/second")
will pop the current route and return the String
"/second" as the result of that route.
If this route was pushed, it received a Future
that will resolve with this String
when it's popped.
If you would have your page that pops the result on /myNextRoute, the following snippet, would return "/second" as the result.
final result = await Navigator.pushNamed(context, "/myNextRoute");
So I assume you would want to return the contact
, so just use
// on the first screen
final contact = await Navigator.pushNamed(context, "/myNextRoute");
// on the second screen
Navigator.pop(context, contact);
Upvotes: 6