nextOptimisticIntId function
Generate a client-side temporary integer primary key for optimistic inserts. Returns a negative microsecond-timestamp so it cannot collide with server-assigned positive IDs.
For UUID / String primary keys, use Uuid().v4() or your own scheme
instead.
final tempId = nextOptimisticIntId();
await client.reducers.createNote(
title: 'Hi',
body: 'there',
optimisticChanges: [
OptimisticChange.insertRow(client.note, Note(id: tempId, title: 'Hi', body: 'there')),
],
);
Implementation
int nextOptimisticIntId() => -DateTime.now().microsecondsSinceEpoch;