@@ -9,22 +9,21 @@ Manage a Sync Session - Flutter SDK
9
9
:values: tutorial
10
10
11
11
.. meta::
12
- :description: Pause and resume sync sessions and monitor sync upload progress
13
- with the Atlas Device SDK for Flutter.
12
+ :description: Access the syncSession to check network connection, pause and resume sync sessions, and monitor Sync progress with the Atlas Device SDK for Flutter.
14
13
15
14
.. contents:: On this page
16
15
:local:
17
16
:backlinks: none
18
17
:depth: 2
19
18
:class: singlecol
20
19
21
- When you use Atlas Device Sync, the Realm Flutter SDK syncs data with Atlas
20
+ When you use Atlas Device Sync, the Flutter SDK syncs data with Atlas
22
21
in the background using a sync session. The sync session starts whenever
23
22
you open a synced realm.
24
23
25
24
The sync session manages the following:
26
25
27
- - Uploading and downloading changes to the realm
26
+ - Uploading and downloading changes to the synced database
28
27
- Pausing and resuming sync
29
28
- Monitoring sync progress
30
29
- Monitoring network connectivity
@@ -54,7 +53,7 @@ to download to your synced realm, call :flutter-sdk:`Session.waitForDownload()
54
53
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.wait-upload-download.dart
55
54
:language: dart
56
55
57
- You can add an optional :flutter-sdk:`CancellationToken
56
+ You can add an optional :flutter-sdk:`CancellationToken
58
57
<realm/CancellationToken-class.html>` to ``waitForUpload()`` and
59
58
``waitForDownload()``.
60
59
@@ -87,36 +86,41 @@ When to Pause a Sync Session
87
86
88
87
.. _flutter-monitor-sync-progress:
89
88
90
- Monitor Sync Upload Progress
91
- ----------------------------
89
+ Monitor Sync Upload and Download Progress
90
+ -----------------------------------------
92
91
93
- To monitor Sync upload progress progress, call :flutter-sdk:`SyncSession.getProgressStream()
92
+ .. versionchanged:: 2.0.0
93
+ ``transferredBytes`` and ``transferrableBytes`` deprecated in favor of ``progressEstimate``
94
+
95
+ To monitor Sync progress, call :flutter-sdk:`SyncSession.getProgressStream()
94
96
<realm/Session/getProgressStream.html>`. This method returns a Stream of
95
- :flutter-sdk:`SyncProgress <realm/SyncProgress-class.html>` objects.
96
- ``SyncProgress`` provides the total number of transferrable bytes and the remaining
97
- bytes to be transferred.
97
+ :flutter-sdk:`SyncProgress <realm/SyncProgress-class.html>` objects that provide
98
+ a ``progressEstimate`` for the current upload or download.
99
+
100
+ The provided ``progressEstimate`` is a double whose value
101
+ ranges from ``0.0`` to ``1.0``. At ``1.0``, the progress stream is complete.
98
102
99
103
``SyncSession.getProgressStream()`` takes two arguments:
100
104
101
105
- A :flutter-sdk:`ProgressDirection <realm/ProgressDirection.html>`
102
- enum that must be set to ``upload``.
103
- This specifies that the progress stream tracks uploads .
106
+ enum that can be set to ``upload`` or ``download``. Specifies whether the
107
+ progress stream monitors upload or download progress .
104
108
105
109
- A :flutter-sdk:`ProgressMode <realm/ProgressMode.html>` enum
106
- that can be set to ``reportIndefinitely`` or ``forCurrentlyOutstandingWork``.
107
- ``reportIndefinitely`` sets notifications to continue until the callback is unregistered.
108
- ``forCurrentlyOutstandingWork`` sets notifications to continue until only
109
- the currently-transferable bytes are synced.
110
+ that can be set to one of the following:
111
+
112
+ - ``reportIndefinitely``: Sets notifications to continue until the callback is
113
+ unregistered.
114
+ - ``forCurrentlyOutstandingWork``: Sets notifications to continue until the
115
+ ``progressEstimate`` reaches ``1.0``.
110
116
111
117
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.monitor-progress.dart
112
118
:language: dart
113
119
114
- .. warning:: Do Not Track Downloads
120
+ .. tip::
115
121
116
- The ``ProgressDirection`` enum also has a ``download`` option to track down downloads.
117
- The ``download`` case provides planned future support for download progress notifications.
118
- However, these notifications do not currently provide an accurate indicator of download progress.
119
- Do not rely on ``ProgressDirection.download`` for download progress notifications.
122
+ Use the ``progressEstimate`` to display a progress indicator or estimated
123
+ data transfer percentage.
120
124
121
125
.. _flutter-monitor-network-connection:
122
126
@@ -146,7 +150,7 @@ Manually Reconnect All Sync Sessions
146
150
The Flutter SDK automatically detects when a device regains connectivity after
147
151
being offline and attempts to reconnect using an incremental backoff strategy.
148
152
149
- You can choose to manually trigger a reconnect attempt with the
153
+ You can choose to manually trigger a reconnect attempt with the
150
154
:flutter-sdk:`App.reconnect() <realm/App/reconnect.html>` instead of waiting for
151
155
the duration of the incremental backoff. This is useful if you have a more
152
156
accurate understanding of the network conditions and don't want to rely on
@@ -155,12 +159,12 @@ automatic reconnect detection.
155
159
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.session-reconnect.dart
156
160
:language: dart
157
161
158
- When you call this method, the SDK forces all sync sessions to attempt to
162
+ When you call this method, the SDK forces all sync sessions to attempt to
159
163
reconnect immediately and resets any timers used for incremental backoff.
160
164
161
165
.. important:: Cannot Reconnect Within Socket Read Timeout Duration
162
-
166
+
163
167
The Flutter SDK has an internal default socket read timeout of 2 minutes,
164
- where the SDK will time out if a read operation does not receive any data
165
- within a 2-minute window. If you call ``App.Sync.reconnect()``
168
+ where the SDK will time out if a read operation does not receive any data
169
+ within a 2-minute window. If you call ``App.Sync.reconnect()``
166
170
within that window, the Flutter SDK does *not* attempt to reconnect.
0 commit comments