one<T> method
Reads a document from Localstore and converts it to the specified type.
Implementation
@override
Future<T?> one<T>(String documentID, { String? subcollection }) async {
final deserializer = LS.deserializers[T];
if (deserializer == null) {
throw UnsupportedError('No deserializer found for type: $T. Consider re-generating Firestorm data classes.');
}
DocumentRef ref = LS.instance.collection(T.toString()).doc(documentID);
if (subcollection != null) {
ref = LS.instance.collection(T.toString()).doc(subcollection).collection(subcollection).doc(documentID);
}
Map<String, dynamic>? snapshot = await ref.get();
if (snapshot == null) {
return null;
}
T object = deserializer(snapshot) as T;
return object;
}