I am trying to build a review app. I am trying to filter out reviews that were hidden by user, so I have a following streamBuilder class:
return StreamBuilder(
stream: reviewRef.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final documents =
snapshot.data.docs.where((snapshot) => snapshot.data()
["hidingUserId"] == null ||
snapshot.data()['isHiddenBy'] !=
FirebaseAuth.instance.currentUser.uid).toList();
if (documents.length == 0) {
return Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Container(
height: 60.0,
width: 100.0,
child: Center(
child: Text(language?.noReviews ?? ""),
),
),
);
} else {
return ListView.builder(
padding: padding,
scrollDirection: scrollDirection,
itemCount: documents.length,
shrinkWrap: shrinkWrap,
physics: physics,
itemBuilder: (BuildContext context, int index) {
return itemBuilder(context, documents[index]);
},
);
}
} else {
return circularProgress(context);
}
},
);
and then in my readReviews class where I have 5 swipable fragments where all reviews are displayed, by a streamBuilderWrapper, where I sort the stream, and display reviews according to some order, for instance ratings = stars, or likes:
StreamBuilderWrapper(
shrinkWrap: true,
stream: reviewRef
.orderBy('stars', descending: true)
.orderBy('timestamp', descending: true)
.snapshots(),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (_, DocumentSnapshot snapshot) {
Review review= Review.fromJson(snapshot.data());
return review.reviewId != null
? Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: Review(review: reviews),
)
: Container(
child: Center(
child: Text('blahblahblah'),
),
);
},
),
However, my sorting in StreamBuilderWrapper does not work. Posts show some random order, same on all five fragments. Hiding posts, finally works though! Why is ordering not working? thank you for the help.