Created
January 15, 2020 16:18
-
-
Save Blasanka/40080ff2402be5f845080d11c39ca1da to your computer and use it in GitHub Desktop.
Here is how to add complex map to complex map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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