MapFormatHelper extension
Extension on Map that provides utility methods for type conversion and data extraction.
This extension adds methods to safely extract and convert values from a map with default values if the key is not found or if the value cannot be converted.
- on
Methods
-
asAny(
String key, {required dynamic def}) → dynamic -
Available on Map, provided by the MapFormatHelper extension
Retrieves the value associated with thekey
. If the key does not exist, returns thedef
value. -
asBool(
String key, {dynamic def = false}) → bool -
Available on Map, provided by the MapFormatHelper extension
Retrieves the boolean value associated with thekey
. If the key does not exist or the value cannot be parsed as a boolean, returns thedef
value. -
asDouble(
String key, {double def = 0}) → double -
Available on Map, provided by the MapFormatHelper extension
Retrieves the double value associated with thekey
. If the key does not exist or the value cannot be parsed as a double, returns thedef
value. -
asEnum<
T> (String key, List< T> enumValues, {required T def, String stringCleaner(String data)?}) → T -
Available on Map, provided by the MapFormatHelper extension
Retrieves an enum value of typeT
associated with thekey
. If the key does not exist or the value cannot be parsed as an enum, returns thedef
value. -
asInt(
String key, {int def = 0}) → int -
Available on Map, provided by the MapFormatHelper extension
Retrieves the integer value associated with thekey
. If the key does not exist or the value cannot be parsed as an integer, returns thedef
value. -
asList<
T> (String key, {List< T> ? def}) → List<T> -
Available on Map, provided by the MapFormatHelper extension
Retrieves the list of typeT
associated with thekey
. If the key does not exist or the value cannot be parsed as a list, returns thedef
value. -
asListModel<
T> (String key, T delegate(dynamic data), {List< T> ? def}) → List<T> -
Available on Map, provided by the MapFormatHelper extension
Retrieves a list of models of typeT
from the map, using a provided delegate function to parse each item. -
asListModelLess<
T> (String key, T delegate(ModelLess data), {List< T> ? def}) → List<T> -
Available on Map, provided by the MapFormatHelper extension
Retrieves a list of models of typeT
from the map usingModelLess
instances and a provided delegate function to parse each item. -
asMap<
T, K> (String key, {Map< T, K> ? def}) → Map<T, K> -
Available on Map, provided by the MapFormatHelper extension
Retrieves the map of typeT
toK
associated with thekey
. If the key does not exist or the value cannot be parsed as a map, returns thedef
value. -
asNum(
String key, {num def = 0}) → num -
Available on Map, provided by the MapFormatHelper extension
Retrieves the numeric value associated with thekey
. If the key does not exist or the value cannot be parsed as a number, returns thedef
value. -
asRegex(
String key, {String def = r'(\w+)', bool isBase64 = true, bool multiline = true}) → RegExp -
Available on Map, provided by the MapFormatHelper extension
Retrieves a regular expression pattern from the map associated with thekey
. If the key does not exist or the value cannot be parsed as a regex, returns thedef
value. -
asString(
String key, {String def = ''}) → String -
Available on Map, provided by the MapFormatHelper extension
Retrieves the string value associated with thekey
. If the key does not exist, returns thedef
value. -
removeNulls(
) → void -
Available on Map, provided by the MapFormatHelper extension
remove all null values from the map.