MapExtension<T> extension
Map extension to extend Map functionality
This extension allows you to perform various operations on a Map<T, T>
such as checking if a key/value pair exists,
getting the value of a specific key and casting it to a certain type, removing key-value pairs from the map based
on their keys or values, and getting a list from the map.
- on
-
- Map<
T, T>
- Map<
Methods
-
diffKeys<
K, V> (Map< K, V> map) → Map<T, T> - Returns all entries of this map according to keys.
-
diffValues(
Map< T, T> map) → Map<T, T> - Returns all entries of this map according to values.
-
doesntHave(
String key, T value) → bool -
If this map does not contains the given
key
/value
pair. -
getBool(
String key) → bool -
Reads a
key
value of bool type from Map. -
getDouble(
String key, {double? defaultValue}) → double? -
Reads a
key
value of double type from Map. -
getId(
{T? defaultValue}) → T? - Returns the ID of the object if exists otherwise return 0;
-
getInt(
String key, {int? defaultValue}) → int? -
Reads a
key
value of int type from Map. -
getList<
K> (String key) → List< T> - This method retrieves the list associated with the given key from the map. If the key is not present or the value associated with the key is not a list, it returns an empty list of the generic type T.
-
getString(
String key, {String? defaultValue}) → String? -
Reads a
key
value of String type from Map. -
has(
String key, dynamic value) → bool -
Whether this map contains the given
key
/value
pair. -
match(
T condition, [String? byDefault = 'Invalid input']) → Object? - The match() function also works similarly to switch
-
pick(
List< T> keys) → Map<T, T> - This extension method picks specific keys from a map and returns a new map containing only the selected keys and their corresponding values.
-
removeNullValues(
) → Map< T, T> - Returns a new map containing the entries of this map excluding entries with null values.
-
retainKeys(
List< T> keys) → Map<T, T> -
Removes the key/value pairs from the map whose keys are not present in the given
keys
list.