callback function for navigation in Flutter
Asked Answered
F

1

6

In Navigator, we can use .then. for eg:

 Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => XyzScreen(),
        ),
      ).then((value) => _someFuncion());

so is there any way to implement the same in go_router?

Farmhouse answered 30/6, 2022 at 9:0 Comment(2)
so you want to call the function when the user come back from XyzScreen() ?Ronda
Yes, I want to call the function when the user comes back from XyzScreen().Farmhouse
D
0

see https://github.com/flutter/flutter/issues/99663 and

It seems like as a main go_router functionality it is not supported yet. Mainly since it is incompatible with browsers otherwise. Support for fixing this is there, however in the project it has a somewhat low priority.

https://mcmap.net/q/422375/-flutter-go_router-how-to-return-result-to-previous-page here you can find a workaround, by registering a listener when the route changes.
So you could => ignore while on the other page (or even subroutes of that page), call the callback when back on this page + unregister the listener, and unregister the listener if otherwise or sth similar.

Darlleen answered 19/10, 2022 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.