MapExtensions<K, V> extension

Extension methods on Map for safe nested value access and deep merging.

final map = {'user': {'name': 'Alice', 'address': {'city': 'Paris'}}};
map.getPath<String>('user.address.city'); // 'Paris'
map.getPath('user.address.zip');          // null
on

Methods

deepMerge(Map<K, dynamic> other) Map<K, dynamic>

Available on Map<K, V>, provided by the MapExtensions extension

Recursively merges other into this map, returning a new Map.
getPath<T>(String path) → T?

Available on Map<K, V>, provided by the MapExtensions extension

Navigates a dot-separated path into nested Maps and returns the value at the leaf.
tryBool(K key) bool?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the bool value for key, or null if absent or not a bool.
tryDouble(K key) double?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the double value for key, or null if absent or not a double.
tryGet<T>(K key) → T?

Available on Map<K, V>, provided by the MapExtensions extension

Type-safe typed accessor that returns the value for key if it is of type T, otherwise null.
tryInt(K key) int?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the int value for key, or null if absent or not an int.
tryList<T>(K key) List<T>?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the List<T> value for key, or null if absent or not a List<T>.
tryMap<K2, V2>(K key) Map<K2, V2>?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the Map<K2, V2> value for key, or null if absent or not a Map<K2, V2>.
tryString(K key) String?

Available on Map<K, V>, provided by the MapExtensions extension

Returns the String value for key, or null if absent or not a String.