flutter_uploader icon indicating copy to clipboard operation
flutter_uploader copied to clipboard

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

Open kadnan0900 opened this issue 3 years ago • 2 comments

StreamSubscription<UploadTaskResponse> _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'); });

kadnan0900 avatar Jan 20 '21 10:01 kadnan0900

same issue

kyungjoongo avatar Feb 17 '21 22:02 kyungjoongo

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?

matthewjs avatar Feb 18 '21 08:02 matthewjs