Skip to content
Discussion options

You must be logged in to vote

I'd stick with Riverpod but pair it with StreamProvider and AsyncValue instead of pushing raw DocumentSnapshot objects into your UI. Firestore streams emit constantly, so map the data to lightweight models before it reaches the provider.

final itemsStreamProvider = StreamProvider.autoDispose<List<Item>>((ref) {
 return FirebaseFirestore.instance.collection('items').snapshots().map((snap) {
 return snap.docs.map((d) => Item.fromJson(d.data())).toList();
 });
});

For heavy real-time traffic, I pipe the stream through debounceTime(Duration(milliseconds: 300)) or chain distinct() to skip identical payloads. If you are tracking large collections, never stream the entire set. Query with limit()

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@IbrahimElshishtawy
Comment options

Answer selected by IbrahimElshishtawy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Search and Navigation Search, navigate, and understand code on GitHub Question Ask and answer questions about GitHub features and usage Welcome 🎉 Used to greet and highlight first-time discussion participants. Welcome to the community!
5 participants