Flutter循环执行指定次数直至成功
Future<bool> loopRequest({final loopCount = 5}) async { int count = 0; bool b = false; await Future.doWhile(() async { ++count; try { bool result = await Future.delayed(Duration(seconds: 3),()=>false).timeout(Duration(seconds: 2)); if (result) { b = true; return false; } } catch(e) { print('error $e'); } return count < loopCount; }); return b; }

浙公网安备 33010602011771号