'How do I deserialize results of AsyncSnapshot<List<DocumentSnapshot<Map<String, dynamic>>>> into a custom widget

I am using geoflutterfire to get documents of a location within a certain radius. I would like the results to be put into a model class and then each displayed in a listview. Here's my trial (Still a rookie so it's probably all wrong anyway)

 buildTimelinePosts() {
    return StreamBuilder(
      stream:
      geo.collection(
          collectionRef: FirebaseFirestore.instance.collection("userPosts"))
          .within(center: geo.point(
          latitude: position.latitude, longitude: position.longitude),
          radius: 50,
          field: 'position'),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return
            circularProgress();
        }
        List<Post> units = [];
        snapshot.data.documents.forEach(doc){
          units.add(Post.fromDocument(doc));
        };
        return ListView(children: units,);
      },
    );
  }

I'm getting the error The getter 'documents' isn't defined for the type 'Object' How do I go about this?



Sources

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

Source: Stack Overflow

Solution Source