Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Realtime — Flutter SDK

final sub = bunbase.realtime.subscribe(
'collection:posts',
onEvent: (RealtimeEvent<Map<String, dynamic>> event) {
switch (event.event) {
case RealtimeEventType.create:
print('New post: ${event.record}');
case RealtimeEventType.update:
print('Updated: ${event.record}');
case RealtimeEventType.delete:
print('Deleted: ${event.record}');
}
},
);
// Unsubscribe when done:
sub.cancel();

Decode records directly into your model:

final sub = bunbase.realtime.subscribeTyped<Post>(
'collection:posts',
Post.fromJson,
onEvent: (RealtimeEvent<Post> event) {
print(event.record.title);
},
);
final sub = bunbase.realtime.subscribe(
'collection:posts',
options: SubscribeOptions(
events: [RealtimeEventType.create, RealtimeEventType.update],
filter: {'status': 'published'},
ids: ['rec_01J...', 'rec_02K...'], // multi-record subscription
),
onEvent: (e) { ... },
);
FieldTypeDescription
eventsList<RealtimeEventType>?Limit to these event types
filterMap<String, String>?Server-side field filter
idsList<String>?Subscribe to specific record IDs
PatternScope
collection:<name>All changes on a collection
collection:<name>:mineAuth user’s own records
record:<name>:<id>Single record
records:<name>Multiple records (use ids option)

Open the WebSocket before the first subscription:

bunbase.realtime.connect();
bunbase.realtime.disconnect(); // cancels all reconnect timers
await bunbase.realtime.ping(); // throws TimeoutError after 5 s by default

Query which users are currently subscribed to a channel:

final users = await bunbase.realtime.presence('collection:posts');
// List<String> of user IDs
final channels = await bunbase.realtime.getSubscriptions();

When the server sends a session-revocation event (password change, account deletion, etc.) the RealtimeClient automatically clears tokens and calls onAuthRevoked. BunBaseClient wires this to auth.currentUser automatically, so your ValueListenableBuilder will react and redirect to the login page.

AttemptDelay
1500 ms
21 s
32 s
doubles each time
cap30 s

Reconnect fires automatically when the socket closes unexpectedly. Active subscriptions are re-sent on each successful reconnect.