Why does the spread operator in Dart do not clone nested maps? This example shows that the "nested" map on both clones is referring to the same object.
test("test map", () {
// Define sourceA
var sourceA = {
"nested": {
"value": 10
}
};
// Define sourceB
var sourceB = {
"sourceA": {...sourceA}
};
// Clone both sources into two new maps
var m1 = {...sourceA};
var m2 = {...sourceB};
print(m2["sourceA"]!["nested"] == m1["nested"]); // prints true
// Check hash codes
print(m2["sourceA"]!["nested"].hashCode); // prints 480486640
print(m1["nested"].hashCode); // prints 480486640
// Change the nested value of m2
m2["sourceA"]!["nested"]!["value"] = 11;
// Observe it has been changed in m1
print(m1["nested"]!["value"]); // prints 11
});
What I am trying to achieve is to be able to change nested properties on one of the clones only.