[go_router] Support return data from a screen with pop()
Use case
With Navigator, we can push to new screen and await result.
final result = await Navigator.push(
context,
// Create the SelectionScreen in the next step.
MaterialPageRoute(builder: (context) => const SelectionScreen()),
);
Currently go_router is support push, go but it return void.
/// Navigate to a URI location w/ optional query parameters, e.g.
/// `/family/f2/person/p1?color=blue`
void go(String location, {Object? extra}) =>
routerDelegate.go(location, extra: extra);
/// Push a URI location onto the page stack w/ optional query parameters, e.g.
/// `/family/f2/person/p1?color=blue`
void push(String location, {Object? extra}) =>
routerDelegate.push(location, extra: extra);
Expected Behaviour: push, go support return a Future<T> and user can call pop with a result.
This is sample for this feature:
https://docs.flutter.dev/cookbook/navigation/returning-data
Hi there!
I strongly subscribe to this idea. In my opinion, it is a desirable use case. I tried to figure it out how it could be done in this commit
The other similar use case is to support deep pop with result data. For example, we can navigate from Screen A to Screen B to Screen C, and we want to pop to Screen A with the result.
Hi there!
I strongly subscribe to this idea. In my opinion, it is a desirable use case. I tried to figure it out how it could be done in this commit
The other similar use case is to support deep pop with result data. For example, we can navigate from Screen A to Screen B to Screen C, and we want to pop to Screen A with the result.
cool, how can i use this?
👍
Hi there!
I strongly subscribe to this idea. In my opinion, it is a desirable use case. I tried to figure it out how it could be done in this commit
The other similar use case is to support deep pop with result data. For example, we can navigate from Screen A to Screen B to Screen C, and we want to pop to Screen A with the result.
so cool, I need it!!!!
I need it !!!
incase anyone...
you can add it with following
go_router:
git:
url: [email protected]:MrOnyszko/packages.git
ref: pop_with_result
path: packages/go_router
According to documentation its ok use gorouter in combination with navigator apis, it will only affect browsers... other platforms are ok i guess.
You can feel free to use GoRouter and Navigator together like this. However, one thing that using Navigator.push in this way will not do is update the browser's address bar. If you want that, you'll need to use GoRouter.go or GoRouter.push.
@MrOnyszko that's awesome! Have you opened a PR yet?
I opened a PR for this. https://github.com/flutter/packages/pull/2416
@giallon @m7mdra @ssyzh @chenenyu @MrOnyszko @dangngocduc @rodgav @tomassasovsky
Awesome 😎
I'll wait for this feature. Thanks 🙏
I'll wait for this feature. Thanks 🙏
I made a package until implementation. They're still defining architecture, so no expectations for near updates.
https://pub.dev/packages/go_router_flow
Any update on this?
I'd also like to express my interest in this. Right now we're using Navigator.push() for those pages that need it but we'd love to make the full switch to go_router.
@jari-kuipers if you want to make the switch to go_router and be able to return values on pop you can use the fork of go_router I made with the feature implemented, it's called go_router_flow, we're currently using it in production in my company and it's updated to the last version of go_router
go_router_flow
Using this for now, thanks for the fork
Any update on this?
IDK why the dev didn't add this provision in the first place. Shame!
Any news?
@kamami Look at the linked, closed MR. We have to wait on #99112 for this feature to be reconsidered.
@daksh-gargas @kamami if you need this feature you can use go_router_flow, it's a fork of go_router with this implemented
If you are using the base routes only from go_router, you can use the normal Navigator from flutter. It's not necessary use the the pop from go_router, you can use Navigator.of(context).pop(true) from flutter
A workaround I've used for this is to pass a VoidCallback into the extra parameter, and then call that function from the second screen when you pop()
Nasty
@NazarenoCavazzon When to add the latest changes from go_router to go_router_flow?
Any updates 🥲
@8thgencore I recently updated to version 6.2.0
I already add way to pass result to pop when i refactor pop. I think what is missing is the push does not return the future.
will there be a new version with this last PR solving this issue?
@ceokin https://github.com/flutter/packages/pull/3368