API回复:
"loan": [
{
"id": "612",
"icbsid": "55",
"loanId": "null",
"loanAcctNo": "001-063-06881-1",
"productId": "4",
"productName": "Fixed Principal+Int(Adv Pym)",
"approvedDate": "2017-11-13",
"loanAmount": "7359.97",
"loanBalance": "0.0",
"monthsToPay": "36",
"interestRate": "12.0",
"dueDate": "2020-12-13",
"status": "Closed",
"lastPayment": "2020-01-10"
},
{
"id": "4970",
"icbsid": "55",
"loanId": "16",
"loanAcctNo": "001-263-01625-4",
"productId": "6",
"productName": "Regular Long Term",
"approvedDate": "2022-01-27",
"loanAmount": "9934.21",
"loanBalance": "5384.21",
"monthsToPay": "60",
"interestRate": "0.0",
"dueDate": "2027-08-25",
"status": "Disbursed",
"lastPayment": "2022-12-29"
}
]
这是我的代码,运行良好,但我需要过滤status
'@覆盖Future〈List?〉fetchLoanList()异步{
final response = await httpServices.getRequest('mobileAppGetIcbsid?icbsid=001-0000055');
final jsonData = json.decode(response.data);
var map = Map<String, dynamic>.from(jsonData);
var userData = UserModel.fromJson(map);
// userData.loan?.where((element) => element.status == "Closed"); <-- not working for me
return userData.loan;
}我尝试取消注解此代码
userData.loan?.where((element) => element.status == "Closed");`,它可以正常显示数据,但不能过滤状态。我希望仅显示status =="Closed"的数据
2条答案
按热度按时间nbysray51#
.where
将创建一个新的修改列表,但不修改原始列表。重新分配原始列表或返回修改后的列表。在这种情况下,我认为2
更好,因为我们只对列表执行一次过滤操作。同样,
.where
将返回Iterable
,它是List
的超类。由于您的函数返回List
,因此我们必须使用.toList()
将Iterable
转换为List
。1.重新分配原始列表
1.返回修改后的列表
pdsfdshx2#