Returning values from screens?
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.
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.
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.
OK I see now. This will require an API change, most probably not a breaking one. Let me see what I can do.
Hello,
Was there any change for this? I would also love this feature.
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.