我有這張地圖串列,我需要獲取“交易”值:
final assets = [
{
"name": "BRL", "balance": 150.2,
"transactions" : Transaction(from: "someone", amount: 1)
},
{
"name": "US", "balance": 1100.2,
"transactions" : Transaction(from: "someone", amount: 5)
},
];
我試圖做assets[0]['transactions'],但我得到的只是空或“交易”的實體
班上:
class Transaction {
final String id = Random().toString();
final String from;
final double amount;
Transaction({
required this.from,
required this.amount,
});
}
我是新手,請幫助我:)
uj5u.com熱心網友回復:
您可以使用這個dartpad示例在應用程式中查看它
假設您想在串列中顯示您的資料(因為這是每個問題的地圖串列)
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: assets.length,
itemBuilder: (context, index) {
Transaction data = assets[index]['transactions'];
return
ListTile(
leading: Text(data.amount.toString()),
title: Text(data.from.toString()));
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/495060.html
標籤:镖
上一篇:函式運算式不能命名:then(
