starkdmi / download_manager

Isolated download manager with progress, cancellation, pause and resume
https://pub.dev/packages/isolated_download_manager
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

handle with errors #4

Closed shahmirzali49 closed 1 year ago

shahmirzali49 commented 1 year ago

I want to stop downloads and clear when any errors happen. how can I do ? I didn't see anything about in the readme

shahmirzali49 commented 1 year ago

is there listen function for error ?

starkdmi commented 1 year ago

@Shahmirzali-Huseynov

request.events.listen((_) {
   // Progress and Success
}, onError: (_) {
   // Failure
});
shahmirzali49 commented 1 year ago

thanks

shahmirzali49 commented 1 year ago

@starkdmi when I close the internet nothing happens in onError callback. shouldn't it give an error?

starkdmi commented 1 year ago

@Shahmirzali-Huseynov do you expect an error? The downloading continues on re-connect. It's an http package behaviour, maybe there is some timeout though.

shahmirzali49 commented 1 year ago

@starkdmi hmm, I tested yeah you are right.

but also when I go home screen or other when downloading starts, 1,2,3+ minute later the progress stuck, the same number, and does not continue, I don't know. What can I do in this situation?

starkdmi commented 1 year ago

@Shahmirzali-Huseynov, the home screen of your app, or an iPhone home screen?

shahmirzali49 commented 1 year ago

@starkdmi iPhone home screen or switch to other apps. it happens not in debug mode, it happens in real device release mode.

shahmirzali49 commented 1 year ago

@starkdmi I will do some logger in the next few days too for what going on background 😅

starkdmi commented 1 year ago

@Shahmirzali-Huseynov, I see two possibilities: 1) The app was really paused by the system 2) The downloading continues, but not the logging

shahmirzali49 commented 1 year ago

@starkdmi If the progress continues why is not affecting to UI ?

starkdmi commented 1 year ago

@Shahmirzali-Huseynov, you should check the file system, are download directory increasing in size? Keep in mind that Flutter UI has its limitations on work in background mode.

shahmirzali49 commented 1 year ago

okay, I will inform you.

shahmirzali49 commented 1 year ago

Sorry for the late response. I paused when the app went to the background(not terminated) and when back to the app I'm resuming.

note to those who want to know about syntax: I'm using flutter_hooks and riverpod.

useOnAppLifecycleStateChange((previous, current) async {
      appLifecycleState.value = current;
      log('AppLifecycleState $current');
      if (current == AppLifecycleState.resumed) {
        if (ref.read(isolateDownloadNotifierProvider.notifier).isPaused()) {
          ref.read(isolateDownloadNotifierProvider.notifier).resumeDownload();
        }
        log('AppLifecycleState.resumed');
      } else if (current == AppLifecycleState.inactive) { 
        ref.read(isolateDownloadNotifierProvider.notifier).pauseDownload();
      }
    });