Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for exposing download progress #45

Closed
perlatus opened this issue May 9, 2018 · 1 comment
Closed

API for exposing download progress #45

perlatus opened this issue May 9, 2018 · 1 comment

Comments

@perlatus
Copy link

perlatus commented May 9, 2018

A feature I need is exposing download progress to applications. While for smaller files this isn't an issue, my use-case includes absurdly large images, animated GIFs, and videos. I'd like to be able to show download progress in my UI without sidestepping the cache, since not having to download a big file twice is kinda the whole point.

What should the API look like? It should be accessible from flutter_cache_manager as well as flutter_cached_network_image.

I'm thinking usage in applications could look like:

double _progress;

@override
Widget build(BuildContext ctx) {
    return new CachedNetworkImage(
        imageUrl: post.sampleUrl,
        errorWidget: const Icon(Icons.error),
        placeholder: new CircularProgressIndicator(value: _progress),
        onCumulativeBytesReceived: (int bytes) {
            setState(() {
                _progress = bytes / post.fileSize;
            });
        },
    );
}

AFAICT with a StreamedResponse you aren't guaranteed to know the size of the file, so returning a percent complete in the callback isn't always possible. CacheManager.getFile could have a similar callback added to it that gets linked up with the CachedNetworkImage.

I've started changing flutter_cache_manager so it'll be possible to count the bytes as they come (StreamedResponse and await for).

@perlatus
Copy link
Author

Actually while this would still be nice to have, I think an extension of getFileIfCached could be more immediately useful so I can use Android's DownloadManager API for showing download progress. Will open issue/PR for that once it's ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant