我有這個物件串列
const List categories = [
{'title': 'category 1', 'value': 1000},
{'title': 'category 2', 'value': 2000},
{'title': 'category 3', 'value': 3000},
];
我正在嘗試映射此串列以在 Column 小部件中呈現一些 UI,所以我這樣做了
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: categories.map((e) => Category(title: e.title, value: e.value)).toList(),
),
但它給了我這個錯誤

uj5u.com熱心網友回復:
在這里,我猜你來自javascript,好吧 dart 有點不同,List 中的元素稱為映射,有Map型別,要從該映射中獲取值,你需要像這樣獲取它:
map["key"]
鍵應該是String,所以在你的情況下,這會很好:
`Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: categories.map((e) => Category(title: e["title"], value:
e["value"])).toList(),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/523345.html
標籤:扑镖
