Flutter go_router how to return result to previous page?
503
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.
Author by
dante
Updated on November 28, 2022Comments
-
dante over 1 year
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?
-
Usama majid about 2 yearsYou need to access the returned data from the 2nd page on the 1st page? Is that what you were trying to say ?
-
dante about 2 yearsI'm asking about go_router package. Not how Navigator.push Navigator.pop work, I know this. go_router do not return Future like Navigation 1.0
-
MaheshPeri19 about 2 yearsI didn't get it that using user input. Can you please add code here to get data back from screen 2 to screen 1 (previous screen) ?
-
Oleg Novosad about 2 years@MaheshPeri19 please follow docs, they are well documented & self-explainable.
-
MaheshPeri19 about 2 yearsSure. Thanks for the reply.
-
Krisztián Velez almost 2 yearsAs I understand, the documentation basically says that there is no way to await a result using the go_router. It suggests you do the data handling in the "user input page" and navigate away when you saved the data without returning to the original page. This means you can't do a simple picker screen (in my case pick a place from a full-screen map). The only way you can do this is to use the plain navigator API and handle everything manually (eg.: navigation guards, route-based providers that are injected by the router, etc.).
-
novas1r1 almost 2 yearsTheres an open issue here: github.com/flutter/flutter/issues/99663. It might solve your problem once its done.