I have a map:
{0: {0:"a",1:"b"}}
Now, on click of button in flutter I want to copy the map to a new key. So it should be
{0: {0:"a",1:"b"},1: {0:"a",1:"b"}}
Now, if I add a new value to key 1, it gets reflected to key 0 also.
So instead of
{0: {0:"a",1:"b"},1: {0:"a",1:"b",2:"c"}}
it becomes
{0: {0:"a",1:"b",2:"c"},1: {0:"a",1:"b",2:"c"}}
Map<int,dynamic> tempMap=new HashMap();
tempMap={...pageMap};
var tempValue=pageMap[pageIndex];
tempMap[(pageIndex+1)]= tempValue;
pageMap.clear();
for (var key in tempMap.keys) {
pageMap.putIfAbsent(key, () => tempMap[key]);
}
Does the map copies by reference in flutter/dart?