Issue
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'
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(),
),
);
Answered By - Sreelal TS
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.