I can’t seem to find any examples on how I would be able to listen to and get notifications on sync state (e.g. syncing, synced, disconnected). The only example in the document shows that I can listen to the sync progress on Realm.open(onProgressCallback) by passing a ProgressCallback.
Am I correct in assuming that ProgressCallback will continue to monitor the sync progress for the entire life of the opened realm? Or is it a once off check on first opened? When the realm has been synced on that initial open, will the callback be continued to get notifications around the progress? If this the case, I could potentially check that 0 transferabble data means it is synced. Meaning that the transferred bytes will jump up and down between 0 and some numbers throughout the life of the opened realm as it continues to sync updates in the background.
I would ideally want to check whether the realm is in a synced state to the remote server before I do some work. I could test the internet connection myself but it won’t guarantee that the realm has been synced.
Hi @lHengl, Thanks for your interest to Ream Sync.
onProgressCallback occurs only while Realm.open is working. Once the Realm.open completes this event handler is dettached. You can be sure that the realm is fully synced after Realm.open completes.
If you want to be sure at any time that the realm is fully synced you can wait waitForUpload() and waitForDownload() to complete before to do your work.
@lHengl
You can also take a look at the other options provided by SysncSession API:
state returning the current state of the session.
connectionState returning the current state of the connection.
connectionStateChanges returns a Stream that emits connection state updates.
pause() pauses synchronization.
resume() resumes synchronization.
waitForUpload/waitForDownload returns a Future that completes when the session uploaded/downloaded all changes.
getProgressStream returns a Stream that emits progress updates.
For more information Session class - realm library - Dart API
Maybe some of them can help for your task.