From 61f44a8760c6d75891edf9843af17368ab15cd58 Mon Sep 17 00:00:00 2001 From: alper <29778028+iamalper@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:59:53 +0300 Subject: [PATCH] refactor: simplify downloading progress calculating --- lib/classes/receiver.dart | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/classes/receiver.dart b/lib/classes/receiver.dart index ea0a3e7..5ff2477 100644 --- a/lib/classes/receiver.dart +++ b/lib/classes/receiver.dart @@ -146,16 +146,10 @@ class Receiver { file = File(join((await _tempDir).path, filename)); file = _generateFileName(file, await _tempDir); } - final totalBytesPer100 = request.contentLength! / 100; - int downloadedBytesto100 = 0; + final totalLengh = request.contentLength!; await for (var bytes in mime) { file.writeAsBytesSync(bytes, mode: FileMode.writeOnly); - - downloadedBytesto100 += bytes.length; - if (downloadedBytesto100 >= totalBytesPer100) { - downloadAnimC?.value += 0.01; - downloadedBytesto100 - totalBytesPer100; - } + downloadAnimC?.value += bytes.length / totalLengh; } final dbFile = DbFile( name: filename,