slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
582 stars 128 forks source link

Issues : context.beamBack(data : {data : example}); #622

Open vfa-tienld opened 1 year ago

vfa-tienld commented 1 year ago

I have 2 screens searchA and Search B , when from SearchA -> SearchB , and SearchB I do back by function context.beamBack(data : data); But in the SearchA screen I don't know how to print or log because the data I pass from the SearchB screen ?

vfa-tienld commented 1 year ago
Screenshot 2023-06-19 at 4 48 57 PM
r-ilagan commented 1 year ago

You need to be able to pass data to SearchA after beaming back from SearchB. Can you show us how your routing is handled?

vfa-tienld commented 1 year ago

It is here

Screenshot 2023-06-20 at 12 21 11 AM Screenshot 2023-06-20 at 12 21 16 AM
vfa-tienld commented 1 year ago

@r-ilagan I don't understand navigator by next router, it is normal to receive data, but when I use beamerBack() to return to searchA, I can't do the same

vfa-tienld commented 1 year ago

@r-ilagan Can you solve this problem? I want to get the value from B ->A and use it directly in the SearchA widget, this value will change when I return

r-ilagan commented 1 year ago

I'm guessing that SearchA is HomeLocation in this case? You can print data in your buildPages() method to see what it contains. Another approach is using a query parameter that you can also access with the state var

vfa-tienld commented 1 year ago

@r-ilagan Yes, you are right, SearchA is HomeLocation, I log data with print(data) command into HomeLocation it already has data from beamerBack What is causing me problem is how to put that data into my SearchA wiget to use, give me an example that can get data from this HomeLocation , thank you very much

r-ilagan commented 1 year ago

No problem. You can make a nullable value in your child for ChangeNotifierProvider that takes in the data object. I would also suggest that you use widgets instead of functions as they are ever slightly more efficient to use. In any case, don't forget to check if data is null before you use it and handle the case when it is null. Good luck

vfa-tienld commented 1 year ago

@r-ilagan Actually here I used Notifier to handle embedding data from beamBack returned, the problem is when back to SearchA it can't update that data variable, so it always has Null value, I need a specific illustration here, please help me

r-ilagan commented 1 year ago

Hmm I'm not too familiar with this approach. Perhaps you can notify your listeners so they can rebuild?

vfa-tienld commented 1 year ago

@r-ilagan So how do you build to get data from beamBack() function ? give me your example