map_enhancer 1.0.2 copy "map_enhancer: ^1.0.2" to clipboard
map_enhancer: ^1.0.2 copied to clipboard

outdated

A plugin which extends Dart's native `Map` type with a couple of handy methods.

example/main.dart

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
}
4
likes
40
pub points
30%
popularity

Publisher

unverified uploader

A plugin which extends Dart's native `Map` type with a couple of handy methods.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on map_enhancer