Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Mar 24, 2025

This extends SyncStatus to report download progress as it happens. Progress is reported as a (completed, total, fraction) triple (where fraction = completed / total) and available:

  1. For entire sync operations: db.currentStatus.downloadProgress.untilCompletion.
  2. For the progress until a specific priority: db.currentStatus.downloadProgress.untilPriority(myPrio).

The best way to get a look and feel for the API may be to look at this example usage:

final status = snapshot.requireData;
final (didSync, progress) = switch (priority) {
null => (
status.hasSynced ?? false,
status.downloadProgress?.untilCompletion
),
var priority? => (
status.statusForPriority(priority).hasSynced ?? false,
status.downloadProgress?.untilPriority(priority)
),
};
if (didSync) {
return child;
} else {
return Center(
child: Column(
children: [
const Text('Busy with sync...'),
LinearProgressIndicator(value: progress?.fraction),
if (progress case final progress?)
Text('${progress.completed} out of ${progress.total}')
],
),
);
}
},
);

In an actual app, it looks like this:

Bildschirmaufnahme.2025-03-31.um.13.27.20.mov

There is some delay in the sync_local commit not included in the progress bar now, but the amount of operations is updated as it should be.

Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the overall structure & apis - just added some implementation comments.

Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check the details of the sync status refactoring, but I'm happy with the overall approach.

@simolus3 simolus3 changed the title WIP: Sync progress status Sync progress status Apr 30, 2025
@simolus3 simolus3 marked this pull request as ready for review April 30, 2025 07:58
@simolus3 simolus3 merged commit 96ea060 into main May 5, 2025
5 checks passed
@simolus3 simolus3 deleted the sync-progress branch May 5, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants