listenToSubCollectionDocument<T> method

StreamSubscription<DocumentSnapshot<Object?>> listenToSubCollectionDocument<T>({
  1. required String collection,
  2. required String documentId,
  3. required String subCollection,
  4. required String subCollectionDocumentId,
  5. required String logReference,
  6. required ValueSetter<DocumentSnapshot<Object?>> onDocumentChange,
})

Implementation

StreamSubscription<DocumentSnapshot> listenToSubCollectionDocument<T>({
  required String collection,
  required String documentId,
  required String subCollection,
  required String subCollectionDocumentId,
  required String logReference,
  required ValueSetter<DocumentSnapshot> onDocumentChange,
}) {
  final StreamSubscription<DocumentSnapshot> streamSubscription = _firebaseFirestore
      .collection(collection)
      .doc(documentId)
      .collection(subCollection)
      .doc(subCollectionDocumentId)
      .snapshots()
      .listen((event) {
    _loggingService
        .log('FirestoreGenericService.listenToSubCollectionDocument.$logReference: New event. Collection: $collection, '
            'DocId: $documentId, SubCollection: $subCollection, SubCollectionDocId: $subCollectionDocumentId');
    onDocumentChange(event);
  });

  return streamSubscription;
}