VDTe
VDTe

Reputation: 645

MappedListIterable<Map,String,List<Map<String,Object>>,dynamic> is not as subtype of type Map<dynamic,dynamic>

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

Expected UI

Upvotes: 1

Views: 625

Answers (1)

Ke1212
Ke1212

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

Related Questions