onPushToRemote method

  1. @override
Future<SyncStatus> onPushToRemote(
  1. LocalFirstEvent localData
)
override

Queues local event for push during the next sync cycle.

This method is called automatically by the LocalFirst framework when a local change needs to be synchronized to the server.

Parameters:

  • localData: The local event to queue for synchronization

Returns:

  • SyncStatus.pending: Event queued successfully, will be pushed on next sync

Behavior:

Unlike WebSocketSyncStrategy which sends events immediately, PeriodicSyncStrategy batches events and sends them during the next sync cycle. This provides:

  • Better network efficiency through batching
  • Reduced server load
  • Lower battery usage on mobile devices

The event is stored in local storage and will be included in the next _performSync call, which happens at syncInterval intervals.

Note: The LocalFirstRepository filters strategies based on repositoryNames before calling this method, so this method will only be called for events that belong to repositories in repositoryNames.

Exceptions: No exceptions are thrown. The event is always queued successfully.

Implementation

@override
Future<SyncStatus> onPushToRemote(LocalFirstEvent localData) async {
  // Events are automatically pushed during the next sync cycle
  // Return pending status to indicate they need to be synced
  LocalFirstLogger.log('Event queued for next sync: ${localData.eventId}', name: logTag);
  return SyncStatus.pending;
}