mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
Use better way to calculate percent for download task
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user