getElement<T> method

Future<T?> getElement<T>(
  1. String collection,
  2. String documentId,
  3. String logReference, {
  4. required T? onDocumentSnapshot(
    1. 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;
  }
}