I am new at Flutter and Firebase, I just want to fetch data from Firestore, for example here, I just want to fetch the value of "KullaniciAdi" from the "[email protected]" document, as simply as possible.
CodePudding user response:
StreamBuilder<QuerySnapshot>(
stream: viewDetails(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
for (int i = 0; i < snapshot.data!.docs.length; i ) {
if (snapshot.data!.docs[i].id == "[email protected]") {
final DocumentSnapshot e = snapshot.data!.docs[i];
dersiniz = "${e["Dersiniz"]}";
return Center(child: Text(dersiniz),);
}
}
},
)
static Stream<QuerySnapshot> viewDetails() {
CollectionReference notesItemCollection = FirebaseFirestore.instance.collection("KullaniciAdi");
return notesItemCollection.snapshots();
}
used like this
CodePudding user response:
I think the structure of the folders is confusing, in general the documents are IDs, like this:
Example:
Collection (users) - Document (sALkf983l3j5RGjsk82lfds) - Fields (name, email, gender)
In this case you could make a call like this:
final FirebaseFirestore firestore = FirebaseFirestore.instance;
final DocumentSnapshot docUser =
await firestore.collection('users').doc('sALkf983l3j5RGjsk82lfds').get();
You can do it:
final FirebaseFirestore firestore = FirebaseFirestore.instance;
final DocumentSnapshot docUser =
await firestore.collection('KullaniciAdi').doc('[email protected]').get();
Editing:
To fetch a specific field value:
final ref = await FirebaseFirestore.instance
.doc('users/$userId').get();
final value = ref.get('name');