flutter icon indicating copy to clipboard operation
flutter copied to clipboard

[go_router] Support return data from a screen with pop()

Open dangngocduc opened this issue 4 years ago • 22 comments

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

dangngocduc avatar Mar 07 '22 08:03 dangngocduc

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.

MrOnyszko avatar Apr 16 '22 12:04 MrOnyszko

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?

rodgav avatar May 16 '22 04:05 rodgav

👍

chenenyu avatar May 17 '22 10:05 chenenyu

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!!!!

ssyzh avatar May 30 '22 07:05 ssyzh

I need it !!!

giallon avatar Jun 29 '22 09:06 giallon

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

m7mdra avatar Jul 03 '22 13:07 m7mdra

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.

source

m7mdra avatar Jul 04 '22 06:07 m7mdra

@MrOnyszko that's awesome! Have you opened a PR yet?

tomassasovsky avatar Jul 09 '22 19:07 tomassasovsky

I opened a PR for this. https://github.com/flutter/packages/pull/2416

@giallon @m7mdra @ssyzh @chenenyu @MrOnyszko @dangngocduc @rodgav @tomassasovsky

NazarenoCavazzon avatar Aug 04 '22 23:08 NazarenoCavazzon

Awesome 😎

giallon avatar Aug 04 '22 23:08 giallon

I'll wait for this feature. Thanks 🙏

booooohdan avatar Oct 23 '22 18:10 booooohdan

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

NazarenoCavazzon avatar Oct 23 '22 18:10 NazarenoCavazzon

Any update on this?

hm-tamim avatar Dec 03 '22 14:12 hm-tamim

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 avatar Dec 04 '22 08:12 jari-kuipers

@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

NazarenoCavazzon avatar Dec 04 '22 13:12 NazarenoCavazzon

go_router_flow

Using this for now, thanks for the fork

Katekko avatar Jan 18 '23 16:01 Katekko

Any update on this?

abdulrojakdev avatar Jan 24 '23 10:01 abdulrojakdev

IDK why the dev didn't add this provision in the first place. Shame!

daksh-gargas avatar Jan 26 '23 19:01 daksh-gargas

Any news?

kamami avatar Jan 31 '23 11:01 kamami

@kamami Look at the linked, closed MR. We have to wait on #99112 for this feature to be reconsidered.

jari-kuipers avatar Jan 31 '23 12:01 jari-kuipers

@daksh-gargas @kamami if you need this feature you can use go_router_flow, it's a fork of go_router with this implemented

NazarenoCavazzon avatar Jan 31 '23 12:01 NazarenoCavazzon

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

Katekko avatar Jan 31 '23 16:01 Katekko

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()

Brandon-Wolff avatar Feb 17 '23 17:02 Brandon-Wolff

Nasty

NazarenoCavazzon avatar Feb 18 '23 14:02 NazarenoCavazzon

@NazarenoCavazzon When to add the latest changes from go_router to go_router_flow?

8thgencore avatar Feb 21 '23 17:02 8thgencore

Any updates 🥲

omar-hanafy avatar Feb 28 '23 07:02 omar-hanafy

@8thgencore I recently updated to version 6.2.0

NazarenoCavazzon avatar Feb 28 '23 13:02 NazarenoCavazzon

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.

chunhtai avatar Mar 03 '23 17:03 chunhtai

will there be a new version with this last PR solving this issue?

ceokin avatar Mar 06 '23 16:03 ceokin

@ceokin https://github.com/flutter/packages/pull/3368

NazarenoCavazzon avatar Mar 06 '23 16:03 NazarenoCavazzon