'Why am I not getting query results from firestore?

I am using geoflutterfire package to get all documents within a certain radius. I am trying to display each document through a model class in a listview. I have my Firestore database structured as: This is the structure of my Firebase database

The code for my StreamBuilder is

 buildTimelinePosts() {
    return StreamBuilder<List<DocumentSnapshot>>(
      stream: geo
          .collection(
              collectionRef: FirebaseFirestore.instance.collection('posts'))
          .within(
              center: geo.point(latitude: -1.3998973, longitude: 36.767642),
              radius: 5000,
              field: 'position'),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return circularProgress();
        }
        snapshot.data!.forEach((doc) {
          nearbyListings.add(Post.fromDocument(doc));
        });
        return ListView(
          children: nearbyListings,
        );
      },
    );
  }

Why am I still getting zero documents even when they are within the radius?



Solution 1:[1]

As far as I can see, userPosts is a subcollection and not a top-level collection. To be able to display user posts within a given geographic area, you have to specify all intermediate references. So a reference like this it will be required:

.collection(collectionRef: FirebaseFirestore.instance
    .collection('posts')
    .doc('109298...')
    .collection('userPosts'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Mamo