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.

Share:
503
dante
Author by

dante

Updated on November 28, 2022

Comments

  • dante
    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
    Usama majid about 2 years
    You need to access the returned data from the 2nd page on the 1st page? Is that what you were trying to say ?
  • dante
    dante about 2 years
    I'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
    MaheshPeri19 about 2 years
    I 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
    Oleg Novosad about 2 years
    @MaheshPeri19 please follow docs, they are well documented & self-explainable.
  • MaheshPeri19
    MaheshPeri19 about 2 years
    Sure. Thanks for the reply.
  • Krisztián Velez
    Krisztián Velez almost 2 years
    As 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
    novas1r1 almost 2 years
    Theres an open issue here: github.com/flutter/flutter/issues/99663. It might solve your problem once its done.