你好,我有一个‘While循环’,它只发生一次,我不知道为什么,它应该发生12次,但它没有.为什么?
以下是我的代码:
Future<List<Evsebillall>> fetcheach() async {
int i=1;
while (i<12) {
print(i);
i++;
String? token = await this.storage.read(key: "token");
Map<String, String> headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer " + (token ?? ""),
};
final response = await http.get(Uri.parse(
this.serverIP + ':' + this.serverPort +
'/user/contractedChargeTransactions?month=$i&year=2022'),
headers: headers);
if (response.statusCode == 200) {
setState(() {
cardBillsTotaleach = jsonDecode(response.body)["cardBillsTotal"] as List;
var resultTotal = cardBillsTotaleach.map((e) => Evsebill.fromJson(e)).toList();
if(resultTotal.isNotEmpty) {
TotalTotaleach = (resultTotal[0].total);
print("totaleach =$TotalTotaleach");
Totaleachlist.add(TotalTotaleach);
}
print ("listtotal =$Totaleachlist");
});
return cardBillsall.map((e) => Evsebillall.fromJson(e)).toList();
}
else{
throw Exception('Failed to load Bills');
}
}
throw Exception('Failed to load Bills');
}