watchNextSyncDuration property
A stream that emits the Duration until the next scheduled auto-sync.
Emits null if no auto-sync is scheduled. The duration will decrease
over time and the stream will emit new values periodically.
Implementation
Stream<Duration?> get watchNextSyncDuration {
return watchNextSyncTime.switchMap((nextSync) {
if (nextSync == null) {
return Stream.value(null);
}
// Emit the duration every second until the sync time is reached.
return Stream.periodic(const Duration(seconds: 1), (_) {
final remaining = nextSync.difference(DateTime.now());
return remaining.isNegative ? Duration.zero : remaining;
}).startWith(nextSync.difference(DateTime.now()));
});
}