listenToDocument<T> method
StreamSubscription<DocumentSnapshot<Object?> >
listenToDocument<T>(
- List<
String> paths, { - required String logReference,
- required ValueSetter<
DocumentSnapshot< onDocumentChange,Object?> >
Listening for the stream of DocumentSnapshot
from Firestore.
In case of any changes - onDocumentChange
will get fired.
paths
is the list of paths to the document. For example: myCollection, documentId
which will
be constructed to myCollection/documentId
.
logReference
is some string for logging purpose.
onDocumentChange
is a ValueSetter which will return object that was changed within
that particular stream.
Implementation
StreamSubscription<DocumentSnapshot> listenToDocument<T>(
List<String> paths, {
required String logReference,
required ValueSetter<DocumentSnapshot> onDocumentChange,
}) {
final pathToDocument = getPathToDocument(paths);
final streamSubscription = _firebaseFirestore.doc(pathToDocument).snapshots().listen((documentSnapshot) {
_loggingService.log('FirestoreHelper.listenToDocument.$logReference: New event. Path: $pathToDocument');
onDocumentChange(documentSnapshot);
});
return streamSubscription;
}