crdt 2.2.2
crdt: ^2.2.2 copied to clipboard

Dart native js
Flutter Android iOS web

Dart implementation of Conflict-free Replicated Data Types (CRDTs).

Dart implementation of Conflict-free Replicated Data Types (CRDTs).

This project is heavily influenced by James Long's talk CRTDs for Mortals and includes a Dart-native implementation of Hybrid Local Clocks (HLC) based the paper Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases.

It has zero external dependencies, so it should run everywhere where Dart runs.

Usage #

The Crdt class works as a layer on top of a map. The simplest way to experiment is to initialise it an empty map:

import 'package:crdt/crdt.dart';

main() {
  // Insert a record
  crdt.put('a', 1);
  // Read the record
  print('Record: ${crdt.get('a')}');

  // Export the CRDT as Json
  final json = crdt.toJson();
  // Send to remote node
  final remoteJson = sendToRemote(json);
  // Merge remote CRDT with local
  // Verify updated record
  print('Record after merging: ${crdt.get('a')}');

// Mock sending the CRDT to a remote node and getting an updated one back
String sendToRemote(String json) {
  final hlc ='another_nodeId');
  return '{"a":{"hlc":"$hlc","value":2}}';

You'll probably want to implement some sort of persistent storage by subclassing the Crdt class. An example using Hive is provided in the parent project.

Example #

An example of how it can be used in an application can be found at

Features and bugs #

Please file feature requests and bugs at the issue tracker.

pub points


Dart implementation of Conflict-free Replicated Data Types (CRDTs).

Repository (GitHub)
View/report issues


API reference


Apache 2.0 (LICENSE)


Packages that depend on crdt