Im trying to calculating some data together . What I have is a videos collection and then each video has a doc id and and then some field for example the uid of the user that uploads this video. And also every video has a sub collection named uservotes. Inside their I saved user voting of this video. This is how It looks
And what I want is getting of one user the user votes rating field calculating together . HERes how I get for one video the rating maybe that will help to understand
FutureBuilder(
future: firebase,
builder:
(BuildContext context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child: Text("loading..."));
} else {
double summe = 0.0;
final docs = snapshot.data.docs;
for (int i = 0;
i < docs.length;
i++) {
summe += (docs[i]['rating']);
print(summe);
}
final possiblestars = docs.length * 5;
print(possiblestars);
return Text(
"${summe.toInt()}/${possiblestars}",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
);
}
}),
The firebase stream is this one
var firebase = FirebaseFirestore.instance
.collection('videos')
.doc(videos.data()['id'])
.collection('uservotes')
.get();
So instead of getting all user votes of one video I wanna get all uservotes of all videos form the same user. You can see that each video in videos collection has uid field and thats the uid of the user that upload the video I can get the current user id with that
final uid= FirebaseAuth.instance.currentUser.uid;
And every video that has saved this uid as uid value Iinside field "uid" in videoscollction is one off the videos that I needed . Then I wanna get of each video the sub collection uservotes all rating to calculating they together . Dont get confused about the same uid doc inside user votes collection thats because the user that uploads this current video also rate his own video . Hope anyone can help .