In my project i am setting up go_router navigation and it works great for navigate, but i found two issues in two cases which i am mentioning below.
- Not found a proper way to pass result in previous page
I have created a common function for routing in the whole app where i have defined all methods push, pop, remove. Now i need to setup a common method where i can pass some data into other screen and also need to get result in previos page when the second screen pop will going to be called.
static go(
{required BuildContext context,
required Mode mode,
required String moveTo,
var param}) async {
try {
switch (mode) {
case Mode.PUSH:
context.push(RouteName.root + moveTo);
break;
case Mode.REPLACE:
context.pushReplacement(RouteName.root + moveTo);
break;
case Mode.REMOVE:
context.go(RouteName.root);
context.pushReplacement(RouteName.root + moveTo);
break;
case Mode.POP:
context.pop();
break;
}
} catch (e) {
print(e);
}
}
- How to get page info during routing
In go_router i am unable to find a way where i can get the current page information if i pop the screen B to screen A. I need to track user activity so in this case i need to fetch the route info when user go or back into any screen. Please guide me if there is any way with go_router.
2
Answers
As far as I know there is currently no way to do this. But someone have made a fork repo & implemented it which you can use.
Its on pub.dev with the name go_router_flow. It’s exactly like the original go_router with this pop with value feature.
Here is some example code:
You can read the discussion here
The package had an update by the nice people 😁🥳 Update to 6.5.5 and checkout docs
Waiting for a value:
Returning a value: