onData property
Handles incoming data updates from Firestore.
This callback is triggered when:
- New document data is received from Firestore
- The user's authentication state changes
The method:
- Updates local state with new document data if user is authenticated
- Clears local state if user is not authenticated
- Marks the service as ready after first update
Parameters:
value
- The new document value from Firestoreuser
- The current Firebase user
Implementation
@override
Future<void> Function(T? value, User? user) get onData {
return (value, user) async {
if (user != null) {
log.debug('Updating doc for user ${user.uid}');
if (value != null) {
upsertLocalDoc(
id: value.id,
doc: (current, _) => value,
);
} else {
_doc.update(null);
}
_isReady.completeIfNotComplete();
log.debug('Updated doc');
} else {
log.debug('User is null, clearing doc');
_doc.update(null);
}
};
}