dispose method
void
dispose()
Clean up all resources and stop syncing.
Call this when you're done with sync (e.g., on app shutdown or user logout). This method:
- Cancels all change listeners
- Disposes all sync helpers
- Closes the change event stream
- Clears internal state
Important: After calling dispose(), this RealmSync instance cannot
be reused. Create a new instance if you need to sync again.
Example:
// On logout or app shutdown
realmSync.dispose();
realm.close();
socket.dispose();
Implementation
void dispose() {
for (final sub in _subscriptions.values) {
try {
sub.cancel();
} catch (_) {}
}
for (final helper in _helpers.values) {
helper.dispose();
}
_subscriptions.clear();
_helpers.clear();
_controller.close();
_started = false;
}