ConflictStrategy enum

Strategies for resolving conflicts when the same document is modified on multiple devices.

A conflict occurs when:

  1. A document is modified on Device A
  2. The same document is modified on Device B before A's changes sync
  3. Device B pulls changes and detects both versions exist

Example:

// Configure conflict strategy during initialization
await SyncLayer.init(
  SyncConfig(
    baseUrl: 'https://api.example.com',
    conflictStrategy: ConflictStrategy.lastWriteWins,
  ),
);
Inheritance
Available extensions

Values

lastWriteWins → const ConflictStrategy

The most recently modified version wins (based on timestamp).

This is the default and most common strategy. It ensures that the latest user intent is preserved, regardless of which device made the change.

Use when: You want the most recent change to always win.

serverWins → const ConflictStrategy

The server (backend) version always wins.

Local changes are discarded if they conflict with the server. This ensures the server is always the source of truth.

Use when: You have server-side validation or business logic that should take precedence over client changes.

clientWins → const ConflictStrategy

The client (local) version always wins.

Remote changes are discarded if they conflict with local changes. This prioritizes the current device's changes.

Use when: You want to ensure local changes are never lost, even if they conflict with the server.

custom → const ConflictStrategy

Use a custom conflict resolver function.

Allows implementing custom conflict resolution logic for specific use cases like merging arrays, summing quantities, or field-level merging.

Use when: Built-in strategies don't fit your use case.

Properties

hashCode int
The hash code for this object.
no setterinherited
index int
A numeric identifier for the enumerated value.
no setterinherited
name String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Constants

values → const List<ConflictStrategy>
A constant List of the values in this enum, in order of their declaration.