File tree 2 files changed +29
-3
lines changed
demos/supabase-todolist/lib/widgets
packages/powersync_core/lib/src
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ class GuardBySync extends StatelessWidget {
27
27
final (didSync, progress) = switch (priority) {
28
28
null => (
29
29
status.hasSynced ?? false ,
30
- status.downloadProgress? .progress
30
+ status.downloadProgress? .untilCompletion
31
31
),
32
32
var priority? => (
33
33
status.statusForPriority (priority).hasSynced ?? false ,
34
- status.downloadProgress? .progressFor (priority)
34
+ status.downloadProgress? .untilPriority (priority)
35
35
),
36
36
};
37
37
@@ -42,7 +42,9 @@ class GuardBySync extends StatelessWidget {
42
42
child: Column (
43
43
children: [
44
44
const Text ('Busy with sync...' ),
45
- LinearProgressIndicator (value: progress),
45
+ LinearProgressIndicator (value: progress? .fraction),
46
+ if (progress case final progress? )
47
+ Text ('${progress .completed } out of ${progress .total }' )
46
48
],
47
49
),
48
50
);
Original file line number Diff line number Diff line change @@ -288,6 +288,12 @@ final class InternalSyncDownloadProgress {
288
288
static const _mapEquality = MapEquality <Object ?, Object ?>();
289
289
}
290
290
291
+ typedef ProgressWithOperations = ({
292
+ int total,
293
+ int completed,
294
+ double fraction,
295
+ });
296
+
291
297
/// Provides realtime progress about how PowerSync is downloading rows.
292
298
///
293
299
/// The reported progress always reflects the status towards the end of a
@@ -322,6 +328,24 @@ extension type SyncDownloadProgress._(InternalSyncDownloadProgress _internal) {
322
328
/// a number between 0 and 1.
323
329
double get progress => _internal._totalDownloaded / _internal._totalTarget;
324
330
331
+ ProgressWithOperations get untilCompletion => (
332
+ total: total,
333
+ completed: downloaded,
334
+ fraction: progress,
335
+ );
336
+
337
+ ProgressWithOperations untilPriority (BucketPriority priority) {
338
+ final downloaded = downloadedFor (priority);
339
+ final total = totalFor (priority);
340
+ final progress = total == 0 ? 0.0 : downloaded / total;
341
+
342
+ return (
343
+ total: totalFor (priority),
344
+ completed: downloaded,
345
+ fraction: progress,
346
+ );
347
+ }
348
+
325
349
/// Returns how many operations have been downloaded for buckets in
326
350
/// [priority] .
327
351
///
You can’t perform that action at this time.
0 commit comments