Created
April 27, 2020 12:32
-
-
Save crizant/6879d122773779d2cc20327ab4e60001 to your computer and use it in GitHub Desktop.
dart_map_enhancer example
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
import 'package:map_enhancer/map_enhancer.dart'; | |
void main() { | |
final Map peter = { | |
'name': { | |
'firstName': 'Peter', | |
'lastName': 'Petrelli', | |
}, | |
'age': 29, | |
}; | |
print( | |
peter.getIn(['name', 'firstName']), | |
); | |
// Output: Peter | |
// or if you prefer the JSON "dot notation": | |
print( | |
peter.getIn('name.firstName'.split('.')), | |
); | |
// Output: Peter | |
// call with default value: | |
print( | |
peter.getIn( | |
'name.nickName'.split('.'), | |
defaultValue: 'Pete', | |
), | |
); | |
// Output: Pete | |
peter.setIn(['ability'], 'Empathic mimicry'); | |
print(peter['ability']); | |
// Output: Empathic mimicry | |
peter.unsetIn(['name', 'lastName']); | |
print(peter['name']['lastName']); | |
// Output: null | |
print(peter.hasIn(['name', 'nickname'])); | |
// Output: false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment