allOfClass<T> method
override
Lists all items of a specific type.
Implementation
@override
Future<List<T>> allOfClass<T>(Type type, { String? subcollection }) async {
if (T.toString() != type.toString()) {
throw ArgumentError("Type mismatch. Attempting to list items of type '${T.toString()}', but parameter type was ${type.toString()}");
}
final deserializer = LS.deserializers[type];
if (deserializer == null) {
throw UnsupportedError('No deserializer found for type: $type. Consider re-generating Firestorm data classes.');
}
var collectionReference = LS.instance.collection(type.toString());
if (subcollection != null) {
collectionReference = collectionReference.doc(subcollection).collection(subcollection);
}
Map<String, dynamic>? items = await collectionReference.get();
if (items == null) {
return [];
}
List<T> objects = [];
//TODO - Consider the use of Multithreading
for (var doc in items.entries) {
if (doc.value != null) {
objects.add(deserializer(doc.value));
}
}
return objects;
}