Skip to content

Instantly share code, notes, and snippets.

@crizant
Created April 27, 2020 12:32
Show Gist options
  • Save crizant/6879d122773779d2cc20327ab4e60001 to your computer and use it in GitHub Desktop.
Save crizant/6879d122773779d2cc20327ab4e60001 to your computer and use it in GitHub Desktop.
dart_map_enhancer example
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