I'm using Future.wait()
to get some data like in the code below:
I call the function Future.delayed()
to wait 1 second between every call because I have a limit set to 1 request per second
await Future.wait([
Future.delayed(const Duration(milliseconds: 1000))
.then((value) => getPartNumber(1)
.then((value) => addPartToList((value.data)))),
Future.delayed(const Duration(milliseconds: 2000))
.then((value) => getPartNumber(2)
.then((value) => addPartToList((value.data)))),
Future.delayed(const Duration(milliseconds: 3000))
.then((value) => getPartNumber(3)
.then((value) => addPartToList((value.data)))),
Future.delayed(const Duration(milliseconds: 4000))
.then((value) => getPartNumber(4)
.then((value) => addPartToList((value.data)))),
]);
所以我想做的是使用循环,而不是手动重复调用4次