- Pure Dart
- Save changes on collection
dependencies:
isar_crdt: ^0.0.1
- extend your models with CrdtBaseObject
- add toJson function and add all the fields you want to sync (include id and sid)
- Create a model to store the crdt changes and extends with CrdtBaseObject
- no need to add anything
// models
@collection
class CarModel extends CrdtBaseObject {
Id id = Isar.autoIncrement;
late String make;
late String year;
@override
Map<String, dynamic> toJson() {
return {
"id": id,
"sid": sid,
"make": make,
"year": year,
};
}
}
@collection
class CrdtEntry extends CrdtBaseObject {}
- add the models including the crdt model to the isar instance
- create a changesync instance and add it to the isar instance
final dir = await getApplicationDocumentsDirectory();
final isar = await Isar.open(
[CarModelSchema, CrdtEntrySchema],
dir: dir.path,
);
final changesSync = IsarCrdt(
store: IsarMasterCrdtStore(
isar.crdtEntrys,
nodeId: "", // change to your own nodeId
builder: () => CrdtEntry(),
sidGenerator: () => uuid.v4(),
),
);
isar.setCrdt(changesSync);
- don't forget to import the packages as they are required as the example shown here above
import 'package:uuid/uuid.dart';
import 'package:isar/isar.dart';
import 'package:isar_crdt/isar_crdt.dart';
import 'package:path_provider/path_provider.dart';
TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.