I started learning dart / flutter on my own initiative.
I have encountered one problem, which I have been trying to solve for the last 3 days.
It is about reading data from the firestore. There are a lot of documents in the firestore. I need a way to read data from multiple query.
I read the data with the streambuilder, and display it with the listview builder.
HomeScreen:
StreamBuilder<List<Vehicle>?>(
stream: database.vehicleStream(user.uid, filters),
builder: (context, snapshot) {
if (snapshot.hasData) { ...
Datebase Service:
Stream<List<Vehicle>?> vehicleStream(String uid, List<ScoutFilter> filters) {
vhTest(uid, filters);
final path = APIPath.vehicle();
final reference = FirebaseFirestore.instance
.collection(path)
.where('datetime', isGreaterThan: limitedTime())
.where('brand', isEqualTo: 'Mercedes-Benz')
.where('model', isEqualTo: 'SL 350')
.orderBy('datetime', descending: true)
.limit(100);
final snapshots = reference.snapshots();
//print(snapshots);
return snapshots.map((snapshot) => snapshot.docs
.map(
(snapshot) => Vehicle.fromMap(snapshot.data(), snapshot.id),
)
.toList());
This works when it comes to one query for "Mercedes-Benz", "SL 350". How do I improve this and have more query for about 30 different vehicles?
Eg.
.where('brand', isEqualTo: 'Tesla')
.where('model', isEqualTo: 'Model 3')
.where('brand', isEqualTo: 'Audi')
.where('model', isEqualTo: 'Q3')
.where('brand', isEqualTo: 'Renault')
.where('model', isEqualTo: 'Clio')
etc.