getLatestServerSyncTime method
Get the latest server sync timestamp from the remote data source.
This timestamp is typically derived from the server_time_synced_at
field
of the most recently synced document.
Returns null if there are no synced items yet.
Implementation
@override
Future<DateTime?> getLatestServerSyncTime() async {
try {
final snapshot = await (await _collectionWithConverter)
.orderBy('server_time_synced_at', descending: true)
.limit(1)
.get();
if (snapshot.docs.isNotEmpty) {
final latestItem = snapshot.docs.first.data();
return latestItem.serverTimeSyncedAt!;
} else {
// Handle the case where there are no documents in the collection yet
return null; // Or any other default value you prefer
}
} catch (e) {
if (kDebugMode) {
_logger.e(
'Error getting latest server sync time from ${_collectionWithConverter.toString()}: $e');
}
rethrow;
}
}