flutter_uploader
flutter_uploader copied to clipboard
uploader.result.listen((result) calls too many times. version flutter_uploader_beta6
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'); });
same issue
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?