[英]How to select an item from a List in flutter
我有這樣一個模型的清單
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
函數返回一個可迭代的對象,然后可以將其轉換為列表。 您應該嘗試這樣的事情:
void setupList() async {
DebtDatabase db = DebtDatabase();
listCache = await db.getMyDebt();
setState(() {
filtered = listCache;
});
List<String> amount = listCache.map((value) => value.amount).toList();
//print(amount);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.