如何将请求顺序发送到服务器?
我有一个列表,我需要将此列表的每个元素顺序发送到服务器。如果答案有错误,则不要继续发送,而是显示错误。我正在尝试使用
await Future.wait([]);
,但我不太了解如何完成“发送失败”,以及如何迭代元素。
通过.foreach(element){}迭代元素 编译器会引发错误:参数类型“列表”无法分配给参数类型“ iToser”
这是我要做的事情:
await Future.wait([
state.revisionFill.forEach((element) {
var successOrFail = await ContainerExpire.call(ContainerExpireParams(token: token, entity: element.entity));
})
]);
我是新手,并且不完全了解flutter中的异步/同步请求。告诉我要学习的方向。 如果下一个发送失败,如何完成下一个发送?
I have a List, and I need to send each element of this List to the server sequentially. And if the answer is with an error, then do not continue sending, but display an error. I am trying to use
await Future.wait([]);
but I do not quite understand how to complete the send on failure, and how to iterate over the elements.
To iterate over elements through .forEach(element) {}
The compiler throws an error: The argument type 'List' can't be assigned to the parameter type 'Iterable<Future>'
Here is what I am trying to do:
await Future.wait([
state.revisionFill.forEach((element) {
var successOrFail = await ContainerExpire.call(ContainerExpireParams(token: token, entity: element.entity));
})
]);
I'm new and don't fully understand async/sync requests in flutter. Tell me which direction to study.
How to complete the next send if it fails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是您要寻找的:
我假设基于继任的价值,您可以判断是否发生错误。基本上,在每个请求之后,您检查状态,并打破错误。您可以添加逻辑以显示错误消息。
This seems to be what you're looking for:
I am assuming that based on the value of successOrFail you can tell whether or not an error occured. Basically after each request you check for the status, and break on an error. You can add logic for displaying your error message.