use the theme color for the done icon and guard status updates on a known task

This commit is contained in:
Santo Shakil 2026-08-11 12:49:23 +06:00
parent 78b352f16f
commit 4706888d10
4 changed files with 18 additions and 17 deletions

View file

@ -65,7 +65,6 @@ class DownloadTaskTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isComplete = status == TaskStatus.complete;
final doneColor = context.isDarkTheme ? Colors.green[200] : Colors.green[400];
final progressPercent = (progress * 100).round();
String getStatusText() => switch (status) {
@ -92,8 +91,7 @@ class DownloadTaskTile extends StatelessWidget {
trailing: IconButton(
icon: Icon(
isComplete ? Icons.download_done : Icons.close,
color: isComplete ? doneColor : context.colorScheme.onError,
size: isComplete ? 28 : null,
color: isComplete ? context.colorScheme.primary : context.colorScheme.onError,
),
onPressed: onCancelDownload,
style: isComplete

View file

@ -20,28 +20,23 @@ class DownloadStateNotifier extends StateNotifier<DownloadState> {
_downloadService.onTaskProgress = _taskProgressCallback;
}
void _updateDownloadStatus(String taskId, TaskStatus status) {
if (status == TaskStatus.canceled) {
void _downloadStatusCallback(TaskStatusUpdate update) {
if (update.status == TaskStatus.canceled) {
return;
}
final existing = state.taskProgress[update.task.taskId];
if (existing == null) {
return;
}
state = state.copyWith(
taskProgress: <String, DownloadInfo>{}
..addAll(state.taskProgress)
..addAll({
taskId: DownloadInfo(
progress: state.taskProgress[taskId]?.progress ?? 0,
fileName: state.taskProgress[taskId]?.fileName ?? '',
status: status,
),
}),
..addAll({update.task.taskId: existing.copyWith(status: update.status)}),
);
}
void _downloadStatusCallback(TaskStatusUpdate update) {
_updateDownloadStatus(update.task.taskId, update.status);
}
void _taskProgressCallback(TaskProgressUpdate update) {
// Ignore if the task is canceled or completed
if (update.progress == -2 || update.progress == -1) {

View file

@ -67,7 +67,6 @@ class DownloadService {
onVideoDownloadStatus?.call(update);
}
// UI-only; saves stay on the DB record stream (#29900)
void _onLivePhotoDownloadCallback(TaskStatusUpdate update) {
onLivePhotoDownloadStatus?.call(update);
}

View file

@ -101,4 +101,13 @@ void main() {
expect(notifier.state.taskProgress.containsKey('ghost'), isFalse);
});
});
test('a status for an unknown task does not create an entry', () {
fakeAsync((async) {
onImage(TaskStatusUpdate(_task('ghost'), TaskStatus.complete));
expect(notifier.state.taskProgress, isEmpty);
expect(notifier.state.showProgress, isFalse);
});
});
}