onData property
Handles incoming data updates from Firestore with post-sync notification.
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
- Marks the service as ready after first update
- Notifies after sync via afterSyncNotifyUpdate
- Clears local state if user is not authenticated
Parameters:
value
- The new document values from Firestoreuser
- The current Firebase user
Implementation
@override
Future<void> Function(List<T>? value, User? user) get onData {
return (value, user) async {
final docs = value ?? [];
if (user != null) {
log.debug('Updating docs for user ${user.uid}');
docsPerIdInformer.update(
docs.toIdMap((element) => element.id),
);
_isReady.completeIfNotComplete();
await afterSyncNotifyUpdate(docs);
log.debug('Updated ${docs.length} docs');
} else {
log.debug('User is null, clearing docs');
docsPerIdInformer.update(
{},
);
await afterSyncNotifyUpdate([]);
}
};
}