Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Created January 15, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blasanka/40080ff2402be5f845080d11c39ca1da to your computer and use it in GitHub Desktop.
Save Blasanka/40080ff2402be5f845080d11c39ca1da to your computer and use it in GitHub Desktop.
Here is how to add complex map to complex map.
void main() {
Map parentMap = {
'childOne': {
'grandSon': {
'grandGrandChild': {
'childOne': 'John',
'childTwo': 'Ron'
}
},
'grandDaughter': {
'grandGrandChild': {
'childOne': 'Lilly',
'childTwo': 'Sholin'
},
},
},
'childTwo': {
'grandSon': {'childOne': 'Charly'}
}
};
Map newMap = {
'childOne': {
'grandSon': {
'grandGrandChild': {
'childOne': 'John',
'childTwo': 'Ron'
}
}
}
};
Map tempParentMap = Map.from(parentMap);
tempParentMap.forEach((key, value) {
if (newMap.containsKey(key)) {
parentMap.addAll(newMap[key]);
}
});
print(parentMap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment