Home > Mobile >  How to insert a list into a map?
How to insert a list into a map?

Time:10-28

I have 2 data one in an array and the other in a list. I need to send these data in API but combine them.

My first data look like this:

data1 = {vendorId: 17, vendorName: Dolphin Bakers};

and second is like this

data2 = [
  {id: 3, province: and, code: 56201},
  {id: 3, province: and, code: 56201},
];

I need to send it like this

{
  vendorId: 17,
  vendorName: Dolphin Bakers,
  data: [
    {id: 3, province: and, code: 56201},
    {id: 3, province: and, code: 56201},
  ],
}

I am trying to add second data in the first data

data1.add(data: data2);

Its showing error Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'add'.

CodePudding user response:

You must put a "data" key in the map:

data1["data"] = data2;
  •  Tags:  
  • dart
  • Related