我有这样一个模型的清单
amount:"12000"
dateTime:"19/07/2018"
detail:"Soto"
hashCode:853818549
id:1
name:"Theodorus"
我只想选择数量并将其添加到另一个字符串列表中,但是我总是会收到此错误A value of type 'String' can't be assigned to a variable of type 'List<String>'.
,我认为是因为我没有正确执行此操作,这是下面的代码
void setupList() async {
DebtDatabase db = DebtDatabase();
listCache = await db.getMyDebt();
setState(() {
filtered = listCache;
});
List<String> amount = new List<String>();
listCache.map((value) {
amount = value.amount; } );
//print(amount);
}
谁能帮我,所以我可以从这个型号列表中获得安培量清单,然后将所有安培量求和?
该map
函数返回一个Iterable,然后可以将其转换为列表。您应该尝试这样的事情:
void setupList() async {
DebtDatabase db = DebtDatabase();
listCache = await db.getMyDebt();
setState(() {
filtered = listCache;
});
List<String> amount = listCache.map((value) => value.amount).toList();
//print(amount);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句