fluttercommunity / flutter_uploader

background upload plugin for flutter
MIT License
211 stars 140 forks source link

uploader.result.listen((result) calls too many times. version flutter_uploader_beta6 #144

Open kadnan0900 opened 3 years ago

kadnan0900 commented 3 years ago

StreamSubscription _resultSubscription;

_resultSubscription = uploader.result.listen((result) async {
  print("Result Result Result Result Result");
  print("onResponse : " + result.response);
  print(result);
  print(
      'IN MAIN APP: ${result.taskId}, status: ${result.status}, statusCode: ${result.statusCode}, headers: ${result.headers}');

  var tmp = <String, UploadItem>{}..addAll(_tasks);
  tmp.putIfAbsent(result.taskId, () => UploadItem(result.taskId));
  tmp[result.taskId] =
      tmp[result.taskId].copyWith(status: result.status, response: result);

// setState(() => _tasks = tmp); }, onError: (ex, stacktrace) { print('exception: $ex'); print('stacktrace: $stacktrace' ?? 'no stacktrace'); });

kyungjoongo commented 3 years ago

same issue

matthewjs commented 3 years ago

It seems that when restarting a flutter application the first call to enqueue a new upload produces a number of UploadTaskResponses to be fired on the uploader's result.listen channel. These tasks are all marked as Enqueued in their status, but they are in fact previous Complete. I think a workaround is to call clearUploads(), but we can only really do that if all items have been marked as complete.

Out of interest, this plugin was obviously inspired by flutter_downloader which uses sqlite as their persistence mechanism for tasks. Is there any reason this was switched out in favour of a file based persistence framework for tasks?