Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Class 'List<DocumentSnapshot<Object?>>' has no instance getter 'docs'

I want to show users within a certain area but using geo query I am getting an error

Class ‘List<DocumentSnapshot<Object?>>’ has no instance getter ‘docs’.

Receiver: Instance(length:1) of ‘_GrowableList’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Tried calling: docs

  Expanded (
                child:StreamBuilder  (
                  stream:  geo.collection(collectionRef: FirebaseFirestore.instance.collection("users"))
                      .within(
                      radius: radius, field: field, center: geo.point(
                      latitude: Latitude,
                      longitude: Longitude
                  ), ),
                  builder: (BuildContext context, snapshot) {
                    if (snapshot.connectionState == ConnectionState.waiting) {
                      return const Center(
                        child: CircularProgressIndicator(),
                      );
                    }
                    return ListView.builder(
                      scrollDirection: Axis.vertical,
                      shrinkWrap: false,
                      itemCount: snapshot.data.length,
                      itemBuilder: (context, index) =>
                          UserCard(
                            data: (snapshot.data as dynamic).docs[index].data(),
                          ),);
                  },
                )
            ),

>Solution :

you are doing a slight mistake that the geo stream provides a list of DocumentSnapshot object not a QuerySnapshot object as CloudFirestore package does.

So, you don’t have to call snapshot.data.docs, actually snapshot.data is exactly the docs collection.

You can just get the DocumentSnapshot at index by the following code:

return ListView.builder(
  scrollDirection: Axis.vertical,
  shrinkWrap: false,
  itemCount: snapshot.data.length,
  itemBuilder: (context, index) => UserCard(
    data: (snapshot.data as dynamic)[index].data(),
  ),
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading