Last updated:
0 purchases
map enhancer
map_enhancer #
A plugin which extends Dart's native Map type with a couple of handy methods.
Getting Started #
Import the plugin by:
import 'package:map_enhancer/map_enhancer.dart`;
copied to clipboard
Usage #
Let's start with a simple Map:
final Map peter = {
'name': {
'firstName': 'Peter',
'lastName': 'Petrelli',
},
'age': 29,
};
copied to clipboard
Get a nested value: #
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
copied to clipboard
Set a nested value: #
peter.setIn(['ability'], 'Empathic mimicry');
print(peter['ability']);
// Output: Empathic mimicry
copied to clipboard
Remove a nested key: #
peter.unsetIn(['name', 'lastName']);
print(peter['name']['lastName']);
// Output: null
copied to clipboard
Check if a nested key is present: #
print(peter.hasIn(['name', 'nickname']));
// Output: false
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.