Skip to content

crizant/dart_map_enhancer

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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`;

Usage

Let's start with a simple Map:

final Map peter = {
  'name': {
    'firstName': 'Peter',
    'lastName': 'Petrelli',
  },
  'age': 29,
};

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

Set a nested value:

peter.setIn(['ability'], 'Empathic mimicry');
print(peter['ability']);
// Output: Empathic mimicry

Remove a nested key:

peter.unsetIn(['name', 'lastName']);
print(peter['name']['lastName']);
// Output: null

Check if a nested key is present:

print(peter.hasIn(['name', 'nickname']));
// Output: false

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages