0

the collection name is the specific user id i want to retrieve data for the specific user. how can i do that. this is the screen shot of my database 1 i tried this code but it return only the 1st collection because of the array


StreamBuilder(
       stream: Firestore.instance.collection("/userdata").snapshots(),
       builder: (context, snapshot) {
     gnickname = snapshot.data.documents[0]["Nickname"];
     gphotourl = snapshot.data.documents[0]["photoURL"];})    


2
  • You are trying to get all the records in the userdata collection right, but you are only getting the first one? Commented Apr 9, 2020 at 9:51
  • no i want to get a specific data with the help of uid Commented Apr 9, 2020 at 10:36

3 Answers 3

1

To get a specific record based on the uid use, in your case, the following code:

var userData = Firestore.instance.collection("/userdata").document("uid").get();

userData is a DocumentSnapshot so use userData.data object to get the key/value pairs.

Sign up to request clarification or add additional context in comments.

Comments

0

You can do it like that for first collection

   StreamBuilder(
           stream: Firestore.instance.collection("/userdata").snapshots(),
           builder: (context, snapshot) {
         gnickname = snapshot.data.documents.first["Nickname"];
         gphotourl = snapshot.data.documents.first["photoURL"];})

Comments

0

To get specific user you can try:

Firestore.instance.collection('your_collection').document('your_id').snapshots()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.