Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
749 stars 438 forks source link

percentage progress download #330

Closed EmanueleVolpato closed 3 years ago

EmanueleVolpato commented 3 years ago

it would be handy to have the download percentage when I download a file

Faaatman commented 3 years ago

You view the progress using the following:

getFileStream(url, withProgress: true)

Use that stream in a stream builder. if loading is true use snapshot.data as Download progress to get the progress.

var loading = !snapshot.hasData || snapshot.data is DownloadProgress;
Jassirlink commented 3 years ago

is there any example for showing the download progress of file , when i use the above one , it shows the instance of download progress , not getting the exact value

EmanueleVolpato commented 3 years ago

is there any example for showing the download progress of file , when i use the above one , it shows the instance of download progress , not getting the exact value

Future downloadPdf(int index, String url) async { await for (var result in DefaultCacheManager().getFileStream( url, key: index.toString(), withProgress: true, )) { if (result is DownloadProgress) { //print('${result.downloaded} ${result.totalSize}'); var totalSizePdf; totalSizePdf = result.totalSize; if (result.totalSize == null) { totalSizePdf = 10000000; } setState(() { progress[index] = (result.downloaded / 0.00000001) / (totalSizePdf / 0.00000001); percentualeDownload[index] = (result.downloaded / 0.00000001) / (totalSizePdf / 0.00000001) * 100; }); } } } }