DatumSyncMetadata class

Metadata describing the synchronization state for a specific user.

Below is the schema for the sync_metadata table in Supabase/PostgreSQL.

CREATE TABLE public.sync_metadata (
  user_id text NOT NULL,
  last_sync_time text NULL,
  last_successful_sync_time text NULL,
  data_hash text NULL,
  device_id text NULL,
  devices text NULL,
  custom_metadata jsonb NULL,
  entity_counts jsonb NULL,
  sync_status text NOT NULL DEFAULT 'pending'::text,
  sync_version integer NOT NULL DEFAULT 0,
  server_timestamp text NULL,
  conflict_count integer NOT NULL DEFAULT 0,
  error_message text NULL,
  retry_count integer NOT NULL DEFAULT 0,
  sync_duration integer NULL,
  created_at timestamp with time zone NOT NULL DEFAULT now(),
  updated_at timestamp with time zone NOT NULL DEFAULT now(),
  CONSTRAINT sync_metadata_pkey PRIMARY KEY (user_id)
) TABLESPACE pg_default;

Note: The devices and entity_counts fields are stored as JSON strings in the database but parsed into structured Dart objects (Map<String, DateTime> and Map<String, DatumEntitySyncDetails> respectively).

Annotations
  • @immutable

Constructors

DatumSyncMetadata({required String userId, DateTime? lastSyncTime, DateTime? lastSuccessfulSyncTime, String? dataHash, String? deviceId, Map<String, DateTime>? devices, Map<String, dynamic>? customMetadata, Map<String, DatumEntitySyncDetails>? entityCounts, SyncStatus syncStatus = SyncStatus.neverSynced, int syncVersion = 1, DateTime? serverTimestamp, int conflictCount = 0, String? errorMessage, int retryCount = 0, int? syncDuration})
Creates sync metadata.
const
DatumSyncMetadata.fromMap(Map<String, dynamic> json)
Creates SyncMetadata from JSON. Supports both camelCase (Dart convention) and snake_case (database convention) keys.
factory

Properties

allDeviceIds List<String>
Get all device IDs that have synced.
no setter
conflictCount int
Number of conflicts detected during last sync.
final
customMetadata Map<String, dynamic>?
Custom metadata fields.
final
dataHash String?
An optional global hash of all data for high-level integrity checking.
final
deviceCount int
Get the count of devices.
no setter
deviceId String?
Current device identifier.
final
devices Map<String, DateTime>?
Map of all devices that have synced, with their last sync time.
final
entityCounts Map<String, DatumEntitySyncDetails>?
A map of counts for different entity types, allowing tracking of multiple "tables" or data collections.
final
errorMessage String?
Error message from last failed sync.
final
hasConflicts bool
Whether there are conflicts.
no setter
hashCode int
The hash code for this object.
no setterinherited
isLastSyncSuccessful bool
Whether the last sync was successful.
no setter
isNeverSynced bool
Whether sync has never occurred.
no setter
isSyncing bool
Whether a sync is currently in progress.
no setter
lastSuccessfulSyncTime DateTime?
Timestamp of last successful synchronization.
final
lastSyncTime DateTime?
Timestamp of last synchronization attempt (successful or not).
final
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setter
retryCount int
Number of retry attempts for failed sync.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serverTimestamp DateTime?
Server-side timestamp for consistency.
final
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
syncDuration int?
Duration of last sync in milliseconds.
final
syncStatus SyncStatus
Current synchronization status.
final
syncVersion int
Version number for sync protocol compatibility.
final
totalPendingChanges int
Total pending changes across all entities.
no setter
userId String
User ID for this metadata.
final

Methods

copyWith({DateTime? lastSyncTime, DateTime? lastSuccessfulSyncTime, String? dataHash, String? deviceId, Map<String, DateTime>? devices, Map<String, dynamic>? customMetadata, Map<String, DatumEntitySyncDetails>? entityCounts, SyncStatus? syncStatus, int? syncVersion, DateTime? serverTimestamp, int? conflictCount, String? errorMessage, int? retryCount, int? syncDuration}) DatumSyncMetadata
Creates a copy with modified fields.
getDeviceLastSync(String deviceId) DateTime?
Get last sync time for a specific device.
hasDeviceSynced(String deviceId) bool
Check if a specific device has synced.
markConflicts(int conflictCount) DatumSyncMetadata
Creates metadata marking conflicts detected.
markSyncCompleted({String? dataHash, Map<String, DatumEntitySyncDetails>? entityCounts, DateTime? serverTimestamp, int? syncDuration}) DatumSyncMetadata
Creates metadata marking sync as completed successfully.
markSyncFailed({required String errorMessage, bool incrementRetry = true}) DatumSyncMetadata
Creates metadata marking sync as failed.
markSyncStarted() DatumSyncMetadata
Creates metadata marking sync as started.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() Map<String, dynamic>
Converts to a map.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

getRequiredValueFromMap<T>(Map<String, dynamic> map, String camelCaseKey, String snakeCaseKey) → T
Helper method to get a required value from a map that may contain either camelCase or snake_case keys. Throws a FormatException if the key is not found.
getValueFromMap<T>(Map<String, dynamic> map, String camelCaseKey, String snakeCaseKey, {T? defaultValue}) → T?
Helper method to get a value from a map that may contain either camelCase or snake_case keys. Returns the value for the first matching key found, preferring camelCase over snake_case.