0

As I read Future cant be cancelled in flutter. I am downloading multiple files and showing the progress with LinearProgressIndicator. When user press back button and then come to loading screen again LinearProgressIndicator dows not work but from background Future feature keeps loading files.

I want the downloads to stop when user navigates away or I want them to keep visiting the page to check on progress.

Should I use singleton class to track progress value or can you suggest me better way?

Future<void> _initialize() async {
    progressWait(await service.getWaitList(_listCourseWords),
        (completed, total) {
      setState(() {

        _progressValue = completed / total;
      });
      if (completed == total) {
        if (mounted)
          setState(() {
            isFilesDownloaded = true;
          });
      }
    });
}
Emma Alden
  • 129
  • 16
  • It's not clear from your question what you want to happen. Do you want the downloads to stop when user navigates away? Do you want to prevent them from navigating until the downloads complete? Do you want them to keep visiting the page to check on progress? Your intention guides what answer you're going to need. Can you add that to your question? – Curt Eckhart Nov 18 '21 at 19:46
  • @CurtEckhart I want them to keep visiting the page to check on progress. – Emma Alden Nov 20 '21 at 11:59

0 Answers0