Home > Mobile >  How Can I convert this type of List in to map
How Can I convert this type of List in to map

Time:10-12

// this is the list

[{welcome_eap: Welcome to Automation Platform}, {eap_version: V2.1.0}, {iot_enable_platform: IOT Enabled Automation Platform}]

// i want this type of result map =

{welcome_eap: Welcome to Automation Platform, eap_version: V2.1.0, iot_enable_platform: IOT Enabled Automation Platform}

CodePudding user response:

You can construct a new map like this:

const example = [{"welcome_eap": "Welcome to Automation Platform"}, {"eap_version": "V2.1.0"}, {"iot_enable_platform": "IOT Enabled Automation Platform"}];
final result = {for (final entry in example) entry.keys.first: entry.values.first};
print(result);

CodePudding user response:

In list each map can have multiple entries.

Try this,

  final dataMap = {};
  
  for(final data in dataList){
    dataMap.addEntries(data.entries);
  }
  • Related