Skip to content

Commit 0a3b18b

Browse files
authored
DOCSP-37885: Flutter: Update progress notification documentation (#3251)
## Pull Request Info Jira ticket: https://jira.mongodb.org/browse/DOCSP-37885 - [Manage a Sync Session - Flutter SDK](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-37885-dart-progress-notifications/sdk/flutter/sync/manage-sync-session/#monitor-sync-upload-and-download-progress): Replace `transferredBytes` and `transferrableBytes` with `progressEstimate`. Update code example. ### Reminder Checklist Before merging your PR, make sure to check a few things. - [x] Did you tag pages appropriately? - genre - meta.keywords - meta.description - [x] Describe your PR's changes in the Release Notes section - [x] Create a Jira ticket for related docs-app-services work, if any ### Release Notes - **Flutter** SDK - Sync Device Data/Manage Sync Session: Update the progress notification documentation in the "Monitor Sync Upload and Download Progress" section for compatibility with Flexible Sync. ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)
1 parent b5987c8 commit 0a3b18b

File tree

4 files changed

+114
-102
lines changed

4 files changed

+114
-102
lines changed

examples/dart/test/manage_sync_session_test.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ main() {
5555
dynamic streamListener;
5656
streamListener = syncProgress.listen((syncProgressEvent) {
5757
if (called == false) {
58-
expect(syncProgressEvent.transferableBytes > 0, isTrue);
59-
expect(syncProgressEvent.transferredBytes > 0, isTrue);
58+
expect(syncProgressEvent.progressEstimate > 0.0, isTrue);
59+
expect(syncProgressEvent.progressEstimate > 0.0, isTrue);
6060
called = true;
6161
streamListener.cancel();
6262
}
@@ -98,6 +98,7 @@ main() {
9898
// :snippet-end:
9999
expect(realm.syncSession.state, SessionState.active);
100100
});
101+
101102
test("Monitor sync progress", () async {
102103
var isCalled = false;
103104
realm.write(() {
@@ -113,19 +114,23 @@ main() {
113114

114115
late StreamSubscription streamListener;
115116
streamListener = stream.listen((syncProgressEvent) {
116-
if (syncProgressEvent.transferableBytes ==
117-
syncProgressEvent.transferredBytes) {
118-
isCalled = true; // :remove:
119-
// Upload complete
120-
print('Upload complete');
121-
// Stop listening to the Stream
122-
streamListener.cancel();
117+
final progressEstimate = syncProgressEvent.progressEstimate;
118+
119+
if (progressEstimate < 1.0) {
120+
print('Upload progress: ${progressEstimate * 100}%');
123121
}
122+
}, onDone: () {
123+
print("Upload complete");
124+
isCalled = true; // :remove:
125+
}, onError: (error) {
126+
print("An error occurred: $error");
127+
streamListener.cancel();
124128
});
125129
// :snippet-end:
126130
await Future.delayed(Duration(seconds: 1));
127131
expect(isCalled, isTrue);
128132
});
133+
129134
test("Monitor network connection", () async {
130135
var isConnected = false;
131136
// :snippet-start: get-network-connection

source/examples/generated/flutter/manage_sync_session_test.snippet.monitor-progress.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ final stream = realm.syncSession.getProgressStream(
33

44
late StreamSubscription streamListener;
55
streamListener = stream.listen((syncProgressEvent) {
6-
if (syncProgressEvent.transferableBytes ==
7-
syncProgressEvent.transferredBytes) {
8-
// Upload complete
9-
print('Upload complete');
10-
// Stop listening to the Stream
11-
streamListener.cancel();
6+
final progressEstimate = syncProgressEvent.progressEstimate;
7+
8+
if (progressEstimate < 1.0) {
9+
print('Upload progress: ${progressEstimate * 100}%');
1210
}
11+
}, onDone: () {
12+
print("Upload complete");
13+
}, onError: (error) {
14+
print("An error occurred: $error");
15+
streamListener.cancel();
1316
});

source/sdk/flutter/sync/manage-sync-session.txt

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ Manage a Sync Session - Flutter SDK
99
:values: tutorial
1010

1111
.. 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.
1413

1514
.. contents:: On this page
1615
:local:
1716
:backlinks: none
1817
:depth: 2
1918
:class: singlecol
2019

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
2221
in the background using a sync session. The sync session starts whenever
2322
you open a synced realm.
2423

2524
The sync session manages the following:
2625

27-
- Uploading and downloading changes to the realm
26+
- Uploading and downloading changes to the synced database
2827
- Pausing and resuming sync
2928
- Monitoring sync progress
3029
- Monitoring network connectivity
@@ -54,7 +53,7 @@ to download to your synced realm, call :flutter-sdk:`Session.waitForDownload()
5453
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.wait-upload-download.dart
5554
:language: dart
5655

57-
You can add an optional :flutter-sdk:`CancellationToken
56+
You can add an optional :flutter-sdk:`CancellationToken
5857
<realm/CancellationToken-class.html>` to ``waitForUpload()`` and
5958
``waitForDownload()``.
6059

@@ -87,36 +86,41 @@ When to Pause a Sync Session
8786

8887
.. _flutter-monitor-sync-progress:
8988

90-
Monitor Sync Upload Progress
91-
----------------------------
89+
Monitor Sync Upload and Download Progress
90+
-----------------------------------------
9291

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()
9496
<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.
98102

99103
``SyncSession.getProgressStream()`` takes two arguments:
100104

101105
- 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.
104108

105109
- 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``.
110116

111117
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.monitor-progress.dart
112118
:language: dart
113119

114-
.. warning:: Do Not Track Downloads
120+
.. tip::
115121

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.
120124

121125
.. _flutter-monitor-network-connection:
122126

@@ -146,7 +150,7 @@ Manually Reconnect All Sync Sessions
146150
The Flutter SDK automatically detects when a device regains connectivity after
147151
being offline and attempts to reconnect using an incremental backoff strategy.
148152

149-
You can choose to manually trigger a reconnect attempt with the
153+
You can choose to manually trigger a reconnect attempt with the
150154
:flutter-sdk:`App.reconnect() <realm/App/reconnect.html>` instead of waiting for
151155
the duration of the incremental backoff. This is useful if you have a more
152156
accurate understanding of the network conditions and don't want to rely on
@@ -155,12 +159,12 @@ automatic reconnect detection.
155159
.. literalinclude:: /examples/generated/flutter/manage_sync_session_test.snippet.session-reconnect.dart
156160
:language: dart
157161

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
159163
reconnect immediately and resets any timers used for incremental backoff.
160164

161165
.. important:: Cannot Reconnect Within Socket Read Timeout Duration
162-
166+
163167
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()``
166170
within that window, the Flutter SDK does *not* attempt to reconnect.

0 commit comments

Comments
 (0)