Use better way to calculate percent for download task

This commit is contained in:
2024-05-25 21:57:11 +08:00
parent e141800664
commit e9f8c7b346
2 changed files with 10 additions and 2 deletions

View File

@@ -39,7 +39,11 @@ class _TaskView extends State<TaskView> {
switch (widget.task.base.type) {
case TaskType.download:
final progress = widget.task.progress as TaskDownloadProgess;
return progress.downloadedPage / progress.totalPage;
double d = progress.downloadedPage.toDouble();
for (final e in progress.details) {
d += e.total == 0 ? 0 : e.downloaded / e.total;
}
return d / progress.totalPage;
case TaskType.exportZip:
final progress = widget.task.progress as TaskExportZipProgress;
return progress.addedPage / progress.totalPage;

View File

@@ -147,7 +147,11 @@ class _TaskPage extends State<TaskPage> {
}
}
if (p.failedPage == 0) {
final percent = p.downloadedPage / p.totalPage;
double downloaded = p.downloadedPage.toDouble();
for (final e in p.details) {
downloaded += e.total == 0 ? 0 : e.downloaded / e.total;
}
final percent = downloaded / p.totalPage;
final percentText = "${(percent * 100).toStringAsFixed(2)}%";
return Column(children: [
LinearPercentIndicator(