Skip to content
Advertisement

Flutter/Firestore : How do I display data from doc in a ListTile?

I am new to Flutter/Firebase/Firestore etc.. so I am struggling a bit. I want to grab the data from the documents in my ‘users’ collection in Firestore and display it in my account information page. I have spent hours messing around with this and I am stuck. If anybody could help me out that would be wonderful!

Here are some samples of what my code, app, and firestore look like.

Code:

signup.dart – this is the page that creates the doc in Firebase on signup

JavaScript

account.dart – this is the page I want to display my Firestore data on

JavaScript

Firestore Docs – I want to take this data and display it in the account page shown below

Edit: I have the document ids being set as the users email, I wanted to try an easy way to recall the document per account. If this is wrong please let me know.

https://i.stack.imgur.com/53TOS.png

Account Page – These are the fields I want to fill with the data, they all say N/A because I have a separate temporary file that uses constants to set those values

https://i.stack.imgur.com/eoHUE.png

Edit: Edited account.dart throws a _CastError

https://i.stack.imgur.com/YRRz9.png

Advertisement

Answer

I have figured out the solution to my issue. In the _AccountState class I added the following lines of code and it seemed to work for me.

I added this above the _AccountState class..

JavaScript

then inside the class I added this code above the build widget..

JavaScript

After adding that into the state I just declared each variable in the title of my ListTiles and it seemed to work

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement