- Set the conflict strategy to ConflictResolutionStrategy.custom
- Provide a custom resolver function that implements the ConflictResolver type
- The resolver receives both conflicting changes and must return the winning change
- Set the conflictResolutionStrategy to ConflictResolutionStrategy.custom in PocketSyncOptions
- Provide your custom resolver function in the customResolver parameter
Custom Conflict Resolver
The custom conflict resolver function receives two parameters:Parameter | Description |
---|---|
localChange | The local change that conflicts with the remote change |
remoteChange | The remote change that conflicts with the local change |
Example
Property | Type | Description |
---|---|---|
id | String | Unique identifier for the change |
tableName | String | Name of the table being modified |
recordId | String | ID of the record being modified |
operation | ChangeType | Type of operation (insert, update, delete) |
timestamp | int | When the change occurred (milliseconds since epoch) |
version | int | Version number of the change |
synced | bool | Whether the change has been synced to the server |
data | Map<String, dynamic> | The actual data changes for the record |
Import note: The data property should always contain a “old” and “new” key. This is needed to maintain consistency with the default conflict resolution strategy.