many<T> method
Reads multiple documents from Firestore and converts them to a list of the specified type. Sends multiple requests at the same time returns when all are completed.
Implementation
Future<List<T>> many<T>(List<String> documentIDs, { String? subcollection }) async {
final deserializer = FS.deserializers[T];
if (deserializer == null) {
throw UnsupportedError('No deserializer found for type: $T. Consider re-generating Firestorm data classes.');
}
List<T> objects = [];
List<DocumentReference> refs;
if (subcollection != null) {
refs = documentIDs.map((id) => FS.instance.collection(T.toString()).doc(subcollection).collection(subcollection).doc(id)).toList();
}
else {
refs = documentIDs.map((id) => FS.instance.collection(T.toString()).doc(id)).toList();
}
List<DocumentSnapshot> snapshots = await Future.wait(refs.map((ref) => ref.get()));
for (DocumentSnapshot snapshot in snapshots) {
if (snapshot.exists) {
T object = deserializer(snapshot.data() as Map<String, dynamic>) as T;
objects.add(object);
}
}
return objects;
}