9

I'm looking for a way to download large pdf files from an external server with a Flutter application for offline storage.

But downloading a large file (sometimes 100mb+) takes some time. I don't want the app being stuck in a wait function for it to download. What i'm looking for is a download function that has a callback with a progress report (Something like: 250000/500000 bytes done. Doesn't have to be exactly that. Just something that I can work with and make a progress bar out of).

Is this even possible to do in Flutter? The only things I came across were the HTTP library. But that does not seem to have a progress callback and just plainly reading the contents of a http call (Which also doesn't have a progress report). I hope someone has a method for me that I can use to make this happen.

Kind regards, Kevin Walter

EDIT: C# has the perfect example of what I mean
https://stackoverflow.com/a/9459441/2854656

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Kevin Walter
  • 6,507
  • 8
  • 28
  • 32
  • https://stackoverflow.com/questions/57995621/how-to-download-a-file-and-store-it-in-downloads-folder-using-flutter/57997334#57997334 – Amit Prajapati Sep 18 '19 at 16:57

1 Answers1

9
int fileSize;
int downloadProgress = 0;

new HttpClient().get('localhost', 80, '/file.txt')
     .then((HttpClientRequest request) => request.close())
     .then((HttpClientResponse response) {
       fileSize ??= respone.contentLength;
       response.transform(utf8.decoder).listen((contents) {
         downloadProgres += contents.length;
         // handle data
       });
     });
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567