CustomConflictResolverCallback typedef

CustomConflictResolverCallback = Map<String, dynamic> Function(Map<String, dynamic> local, Map<String, dynamic> remote, DateTime localTimestamp, DateTime remoteTimestamp)

Custom conflict resolver callback type.

Allows developers to implement custom conflict resolution logic for specific use cases that the built-in strategies don't handle.

Parameters:

  • local: The local version of the document
  • remote: The remote (server) version of the document
  • localTimestamp: When the local version was last modified
  • remoteTimestamp: When the remote version was last modified

Returns: The resolved version of the document

Example:

// Merge arrays instead of replacing
Map<String, dynamic> mergeArrays(
  Map<String, dynamic> local,
  Map<String, dynamic> remote,
  DateTime localTimestamp,
  DateTime remoteTimestamp,
) {
  return {
    ...remote,
    'tags': [
      ...List<String>.from(local['tags'] ?? []),
      ...List<String>.from(remote['tags'] ?? []),
    ].toSet().toList(),
  };
}

Implementation

typedef CustomConflictResolverCallback = Map<String, dynamic> Function(
  Map<String, dynamic> local,
  Map<String, dynamic> remote,
  DateTime localTimestamp,
  DateTime remoteTimestamp,
);