flutter_redux_navigation icon indicating copy to clipboard operation
flutter_redux_navigation copied to clipboard

Returning values from screens?

Open naiveai opened this issue 6 years ago • 5 comments

Is there a way to return a value from a screen like is demonstrated in https://flutter.dev/docs/cookbook/navigation/returning-data? I know sharing data with the store works, but this also enables the important use case of running some function (like a dispatch to update the state using an async action) whenever a page's back button is pressed.

naiveai avatar Jun 08 '19 17:06 naiveai

Hi @naiveai.

Couldn't you achieve the same result if you use a postNavigation function on NavigateToAction.pop?

I can see in that Navigator.pop API includes a result optional parameter, which is returned upon completion, but as the navigation is being done in the NavigationMiddleware the only way to obtain the result is to set it somewhere in your state ... 🤔 This by itself is a bit complicated as it would make the library state aware in order to set the result in it.

A way around it could be to include an optional user-provided callback function, but it needs some thought put into it.

Please let me know if the postNavigation can work for you otherwise, this will require a new feature.

esarbanis avatar Jun 10 '19 19:06 esarbanis

postNavigation is run immediately after the page is navigated to. What I'm talking about is a callback when the navigator page I've just pushed is popped by the user, by pressing the back button. It's what happens when you use .then on the Future returned by a Navigator.push call.

naiveai avatar Jun 10 '19 19:06 naiveai

OK I see now. This will require an API change, most probably not a breaking one. Let me see what I can do.

esarbanis avatar Jun 10 '19 19:06 esarbanis

Hello,

Was there any change for this? I would also love this feature.

simkepal avatar Nov 27 '20 08:11 simkepal

Hi @simkepal unfortunately I didn't have the time to move forward with it, but I will raise its priority and try to have it done as soon as I find the time.

esarbanis avatar Nov 27 '20 08:11 esarbanis