♻️ Better task overlay progress

This commit is contained in:
2026-01-11 13:11:15 +08:00
parent bf59108569
commit 88c4d648d5
2 changed files with 196 additions and 94 deletions

View File

@@ -256,6 +256,21 @@ class UploadTasksNotifier extends Notifier<List<DriveTask>> {
}).toList();
}
void updateUploadProgress(String taskId, int uploadedBytes, int uploadedChunks) {
state =
state.map((task) {
if (task.taskId == taskId) {
return task.copyWith(
uploadedBytes: uploadedBytes,
uploadedChunks: uploadedChunks,
status: DriveTaskStatus.inProgress,
updatedAt: DateTime.now(),
);
}
return task;
}).toList();
}
void updateDownloadProgress(
String taskId,
int downloadedBytes,
@@ -470,6 +485,7 @@ class EnhancedFileUploader extends FileUploader {
// Step 2: Upload chunks
int bytesUploaded = 0;
int chunksUploaded = 0;
if (fileData is XFile) {
// Use stream for XFile
final subscription = fileData.openRead().listen(null);
@@ -494,6 +510,11 @@ class EnhancedFileUploader extends FileUploader {
},
);
bytesUploaded += chunkData.length;
chunksUploaded += 1;
// Update upload progress in UI
ref
.read(uploadTasksProvider.notifier)
.updateUploadProgress(taskId, bytesUploaded, chunksUploaded);
}
subscription.cancel();
} else if (fileData is Uint8List) {
@@ -521,6 +542,11 @@ class EnhancedFileUploader extends FileUploader {
},
);
bytesUploaded += chunks[i].length;
chunksUploaded += 1;
// Update upload progress in UI
ref
.read(uploadTasksProvider.notifier)
.updateUploadProgress(taskId, bytesUploaded, chunksUploaded);
}
} else {
throw ArgumentError('Invalid fileData type');
@@ -530,4 +556,4 @@ class EnhancedFileUploader extends FileUploader {
onProgress?.call(null, Duration.zero);
return await completeUpload(taskId);
}
}
}