Obj class

Static utility methods for working with maps using dot notation.

final user = {'profile': {'name': 'Anna', 'age': 30}};
Obj.get(user, 'profile.name');     // 'Anna'
Obj.has(user, 'profile.email');    // false
Obj.set(user, 'profile.email', 'a@b'); // mutates user
Obj.dot(user);                     // {'profile.name': 'Anna', 'profile.age': 30}

Available helpers:

Read:

Typed read:

Write (mutating):

Subset:

Filter:

Transform:

Flatten / inflate:

Merge / compare / query:

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

add(Map map, String key, dynamic value) → Map
Adds value at key only if no value currently exists there.
deepEquals(dynamic a, dynamic b) → bool
Returns true when a and b are structurally equal.
divide<K, V>(Map<K, V> map) → List<List>
Splits map into a [keys, values] pair.
dot(Map map, [String prefix = '']) → Map<String, dynamic>
Flattens a nested map into a single-level map keyed by dot-paths.
except<K, V>(Map<K, V> map, Iterable<K> keys) → Map<K, V>
Returns a new map containing all entries except those whose keys are in keys.
exists(Map map, Object key) → bool
Returns true when map has key at the top level (no traversal).
flip<K, V>(Map<K, V> map) → Map<V, K>
Swaps keys ↔ values. When values collide, the last entry wins.
forget(Map map, String key) → Map
Removes key (dot notation) from map. Returns the map for chaining.
get(Map map, String key, [dynamic defaultValue]) → dynamic
Returns the value at key in map using dot notation, or defaultValue when the path is missing.
getBool(Map map, String key, [bool? defaultValue]) → bool?
Returns the value at key coerced to bool, or defaultValue.
getDouble(Map map, String key, [double? defaultValue]) → double?
Returns the value at key coerced to double, or defaultValue.
getInt(Map map, String key, [int? defaultValue]) → int?
Returns the value at key coerced to int, or defaultValue.
getList(Map map, String key, [List? defaultValue]) → List?
Returns the value at key when it is a List, otherwise defaultValue.
getMap(Map map, String key, [Map? defaultValue]) → Map?
Returns the value at key when it is a Map, otherwise defaultValue.
getString(Map map, String key, [String? defaultValue]) → String?
Returns the value at key coerced to String, or defaultValue.
has(Map map, String key) → bool
Returns true when map has a value at key (dot notation).
hasAll(Map map, Iterable<String> keys) → bool
Returns true when every one of keys resolves in map.
hasAny(Map map, Iterable<String> keys) → bool
Returns true when any of keys resolves in map.
mapKeys<K, V, K2>(Map<K, V> map, K2 fn(K)) → Map<K2, V>
Returns a new map with each key transformed by fn.
mapValues<K, V, V2>(Map<K, V> map, V2 fn(V)) → Map<K, V2>
Returns a new map with each value transformed by fn.
merge(Map target, Map source) → Map<String, dynamic>
Recursively merges source into target and returns a new map. On key collision, source wins; nested maps are merged.
only<K, V>(Map<K, V> map, Iterable<K> keys) → Map<K, V>
Returns a new map containing only the entries whose keys are in keys.
prependKeysWith<V>(Map<String, V> map, String prefix) → Map<String, V>
Prefixes every top-level key in map with prefix.
pull(Map map, String key, [dynamic defaultValue]) → dynamic
Returns the value at key and removes it from map.
query(Map<String, dynamic> map) → String
Encodes map as a URL query string.
set(Map map, String key, dynamic value) → Map
Sets value at key in map, creating nested maps along the path. Mutates map in place and returns it for chaining.
undot(Map<String, dynamic> map) → Map<String, dynamic>
Inflates a dot-keyed map back into a nested structure.
whereNotEmpty<K, V>(Map<K, V> map) → Map<K, V>
Returns a new map with entries whose values are null or empty (empty String, Iterable, or Map) removed.
whereNotNull<K, V>(Map<K, V?> map) → Map<K, V>
Returns a new map with entries whose values are null removed.