getElement<T> method
Future<T?>
getElement<
T>( - String collection,
- String documentId,
- String logReference, {
- required T? onDocumentSnapshot(
- DocumentSnapshot<Object?> documentSnapshot
),
})
Implementation
Future<T?> getElement<T>(
String collection,
String documentId,
String logReference, {
required T? Function(DocumentSnapshot documentSnapshot) onDocumentSnapshot,
}) async {
try {
_loggingService.log('FirestoreGenericService.getElement.$logReference: Collection: $collection, DocId: $documentId');
final DocumentSnapshot documentSnapshot = await _firebaseFirestore.collection(collection).doc(documentId).get();
final T element = onDocumentSnapshot(documentSnapshot)!;
return element;
} catch (e) {
_loggingService.log(
'FirestoreGenericService.getElement.$logReference: Collection: $collection, DocId: $documentId, Exception: $e',
logType: LogType.error,
);
return null;
}
}