Flutter go_router how to return result to previous page?

Viewed 3215

I'm trying to open a page and get returned result with go_router package. In Navigation 1.0 I use this:

final result = await Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => const SecondRoute()),
);
// handle result

But I can't seem to do it with go_router. Any solution or explaination?

2 Answers

This flow is described in the docs here: https://gorouter.dev/user-input

Generally you have to update the data and return some value back as a route with params and the screen itself should manage updates / data manipulation.

I don't want to copy paste their code here, but the answer you are looking for is in the docs page above.

When you are done with the next screen just use Navigator.pop(context,true); and true is something that you want to send to the previous screen. You can send anything I'm just using true for reference. This will allow your result variable to get data and perform anything.

Related