Flutter Firestore QuerySnapshot has no instance of getter 'documentID'

Viewed 36

I get an error that "QuerySnapshot that has no instance of getter 'documentID'".

    StreamBuilder(
      stream: FirebaseFirestore.instance.collection("CHAT").orderBy("createdAt",descending: true).snapshots(),
      builder: (ctx,AsyncSnapshot snapshot){
        if(snapshot.connectionState==ConnectionState.waiting)
        {
           return  Center(child:  CircularProgressIndicator(color:Colors.green[300]));
        }
       else {
            var doc=snapshot.data!.docs;
            var user=FirebaseAuth.instance.currentUser;
            return ListView.builder(
              reverse: true,
              itemCount: doc.length,
              itemBuilder: (BuildContext ctx,index){
                 return BubbleMessage(
                   key: ValueKey(doc[index].documentID),
                   //:::::::::::::::get Message From firebase :::::::::::

                   message:doc[index]['message'],

                   //we check if the id isMe or the Other Person
                   isMe: doc[index]['userId']==user!.uid,

                   //::::::::::::::get  username From Firebase ::::::::::::::::::
                   username: doc[index]['username'],
 
          );
        },
             
     );

Why am I unable to access the documentID?

1 Answers

The getter of the ID is just .id, not .documentID. See here. I'd recommend using your IDE's autocomplete to see what getters are available.

In the majority of cases the documentation on Flutter packages are extremely well documented and visible from within your IDE.

Taken from my IDE

Related