Dart SDK - Realtime#

Subscribe to table changes with two transports:

  • centrifugo - WebSocket to the realtime server. One persistent connection, auto-reconnect with backoff. Recommended for scale.
  • sse - Server-Sent Events stream over plain HTTP.
  • auto (default) - WebSocket via Centrifugo.

Subscribe#

final sub = db.realtime.subscribe(
  'messages',
  (event) => print('${event.type}: ${event.record}'),
  options: const SubscribeOptions(
    events: ['INSERT', 'DELETE'],       // optional filter
    transport: RealtimeTransport.auto,  // auto | centrifugo | sse
  ),
);

// Stop listening
sub.unsubscribe();
DART

event is a RealtimeEvent:

FieldType
idString
typeString - INSERT / UPDATE / DELETE
tableString
projectIdString
recordMap<String, dynamic>
oldRecordMap<String, dynamic>? (UPDATE/DELETE)
createdAtString?

How it works#

  1. The SDK calls POST /projects/{id}/realtime/connect?table=... and receives a scoped token and channel.
  2. It opens a Centrifugo WebSocket ({url}/connection/websocket) and sends {"id":1,"connect":{"token":token}}.
  3. The SSE transport reads /projects/{id}/realtime/events?... directly.
  4. Both transports auto-reconnect with exponential backoff (1s..30s).

Event payload#

{
  "id": "uuid",
  "type": "INSERT",
  "table": "messages",
  "project_id": "5c73dab0-...",
  "record": { "id": "...", "message": "hello" },
  "old_record": null,
  "created_at": "2026-10-03T20:47:34Z"
}
JSON

Next: Storage.