MapExtensions<K, V> extension

A collection of helpful extensions on Map to reduce boilerplate.

on

Methods

containsAllKeys(List<K> keys) bool

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

Returns true if the map contains all the specified keys. Example: map.containsAllKeys(['name', 'age'])
deepCopy() Map<K, V>

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

Creates a deep copy of the map. Example: final cloned = map.deepCopy()
getBool(K key, {bool defaultValue = false}) bool

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

Safely gets a bool value from the map. Example: map.getBool('isActive', defaultValue: false)
getDouble(K key, {double defaultValue = 0.0}) double

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

Safely gets a double value from the map. Example: map.getDouble('price', defaultValue: 0.0)
getInt(K key, {int defaultValue = 0}) int

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

Safely gets an int value from the map. Example: map.getInt('age', defaultValue: 0)
getList<T>(K key, {List<T> defaultValue = const []}) List<T>

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

Safely gets a List from the map. Example: map.getList<String>('tags')
getMap<K2, V2>(K key, {Map<K2, V2> defaultValue = const {}}) Map<K2, V2>

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

Safely gets a nested Map from the map. Example: map.getMap<String, dynamic>('user')
getString(K key, {String defaultValue = ''}) String

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

Safely gets a String value from the map. Example: map.getString('name', defaultValue: 'Unknown')
removeNulls() Map<K, V>

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

Alias for removeNullValues.
removeNullValues() Map<K, V>

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

Returns a new map with all null values removed. Example: map.removeNullValues()