Reputation: 645
I have a widget that accepts final Map<String, List> transactions;, but getting the error in title. How do I parse the response to get the ff. Map<String, List>
Have tried to pass it with:
Map<String, dynamic> paymentsResponse = MockResponse.getAccountHistory();
final Map<String, List<PaymentTransactionList>> transactionList = Map<String, List<PaymentTransactionList>>.from(
paymentsResponse['transaction_list'].map(
(transaction) => PaymentTransactionList.fromJson(transaction)));
PaymentTransactionHistoryList(paymentsResponse['transaction_list'])
API Response
"transaction_list": [
{
"july": [
{
"stan": 1,
"timestamp": "2019-02-04 06:22:07",
"amount": -28755.77,
}
],
},
]
Widget
class PaymentTransactionHistoryList extends StatelessWidget {
final Map<String, List<PaymentTransactionList>> transactions;
PaymentTransactionHistoryList(this.transactions);
@override
Widget build(BuildContext context) {
List<Widget> widgets = [];
transactions.forEach((key, value) {
widgets.add(PaymentListGroup(key, value));
});
return Column(
children: widgets,
);
}
}
Expected UI
Upvotes: 1
Views: 625
Reputation: 129
Try to add ".tolist" at the end
Map<String, List>.from(paymentsResponse['transaction_list'].map( (transaction) => PaymentTransactionList.fromJson(transaction)).tolist)
it should resolve the issue.Thanks
Upvotes: 0