mark
mark

Reputation: 1295

adding value for map which is key of other map in DART

I have a map like this,

"data":{ 
      "date":"Date",
      "time":"Time",
      "from":"From",
      "to":"To",
      "color":"Color",
      "state":"State",
      "country":"Country"
   },

I want to create another map that should look like this, map header; which should contain,

header {
"1":"date",
"2":"time",
"3":"from",
"4":"to",
"5":"color",
"6":"state",
"7":"country",
}

I am not getting how to add the key of another map as a value to header map, and also adding key starts form 1.

can anyone help me on this thanks

Upvotes: 0

Views: 281

Answers (2)

Mattia
Mattia

Reputation: 6524

Here is another way to achieve that:

var i = 1;
Map.fromIterable(data.keys, key: (_) => i++);

Upvotes: 0

thuva4
thuva4

Reputation: 1225

In Dart, you can do something like this.

var header = data.keys.toList().asMap().map((index, value)=> MapEntry(index+1, value));

Upvotes: 1

Related Questions