skip to Main Content

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.

2

Answers


  1. 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');
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search