turnOnRealtimeSync method
Implementation
Future<StreamSubscription<bool>> turnOnRealtimeSync() async {
_logger.d('[OfflineFirstRepository] Turning on real-time sync');
await turnOffRealtimeSync(); // Ensure any existing subscription is cancelled
_realtimeSyncSubscription =
(await remoteRepository.watchingNewRecordsUpdates()).listen(
(hasUpdates) {
_logger.d(
'[OfflineFirstRepository] watchingNewRecordsUpdates - Received update notification. Has updates: $hasUpdates');
if (hasUpdates) {
_logger.d(
'[OfflineFirstRepository] hasUpdates and try to sync and fetch data');
_throttledSync();
}
}, onDone: () {
_logger.d(
'[OfflineFirstRepository] watchingNewRecordsUpdates - Received update notification. onDone');
}, onError: (e) {
_logger.e(
'[OfflineFirstRepository] watchingNewRecordsUpdates - Received update notification. onError:(${e})');
});
_logger.d('[OfflineFirstRepository] Real-time sync turned on');
return _realtimeSyncSubscription!;
}