Hi i am new to cloud firestore. I am using a StreamBuilder with a ListView.builder inside to get the documents from firestore. I was wondering which one of these would be a better approach.

  1. Getting all documents index by index inside ListView.builder
ListView.builder(itemBuilder: (context, index){
                  final time = snapshot.data.documents[index].data['time'];
                  final date = snapshot.data.documents[index].data['date'];
                  final location = snapshot.data.documents[index].data['location'];
                  final eventName = snapshot.data.documents[index].data['event_name'];
                  return UpcomingEventCard(
                    time: time,
                    date: date,
                    location: location,
                    eventName: eventName,
                  );
                },itemCount: snapshot.data.documents.length,
                )
  1. Getting all the documents at once first and then using the list inside ListView.bulder, for example like this
final eventSnapshots = snapshot.data.documents;
ListView.builder(itemBuilder: (context, index){
                  final time = eventSnapshots[index].data['time'];
                  final date = eventSnapshots[index].data['date'];
                  final location = eventSnapshots[index].data['location'];
                  final eventName = eventSnapshots[index].data['event_name'];
                  return UpcomingEventCard(
                    time: time,
                    date: date,
                    location: location,
                    eventName: eventName,
                  );
                },itemCount: snapshot.data.documents.length,
                )

Both looks same from logic point of view (maybe i am overthinking) but i am worried if any costs more no of reads than other since i am using free Spark Plan. I do need to get all the documents inside the collection.


Solution 1: Doug Stevenson

I do need to get all the documents inside the collection.

If you need all documents in a collection, then it will cost 1 read for each of the documents. That is all you need to know from a billing perspective. What you do with a query snapshot after it's delivered to the client is completely up to you and has no effect on billing, since everything in is memory at that point. Choose whichever one you're more comfortable with.