Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter : Can't access data passed from another screen

I’m trying to build 2 screens one contains a list of products and the second has product details, I’m using firebase to store data and so I fetch the data from Firestore in the first screen and it all works perfectly.
However in the second screen I pass product data correctly using Navigator but I cannot use that data in my ui, here is code for my second screen,
Second screen Code

As you can see I cannot use the name variable in my widget tree, i’ve seen videos on youtube and I found that some people use state management to solve this problem, but for my case I just want to pass data and display it so…
thank you in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The way you’ve passed data is correct but the way you’ve accessed the data isn’t.

Whenever you try to access the variables of a Class in its state, you do that using widget. So, to access the name or other variables, just do as follows:

widget.name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading