restoreCache static method

void restoreCache({
  1. required Duration offset,
  2. DateTime? syncTime,
})

Restores a previously saved offset (e.g. from SharedPreferences or secure storage) to enable offline-first accuracy on application startup.

Implementation

static void restoreCache({
  required Duration offset,
  DateTime? syncTime,
}) {
  final nowLocal = DateTime.now();
  _cachedOffset = offset;
  _lastSyncTime = syncTime ?? nowLocal;
  _lastSyncElapsed = _stopwatch.elapsed;
  _lastSyncDetails = NtpResponse(
    dateTime: nowLocal.add(offset),
    offset: offset,
    roundTripDelay: Duration.zero,
    server: 'cache',
    referenceId: 'CACH',
  );
}