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 thedefvalue. -
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 thedefvalue. -
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 thedefvalue. -
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 typeTassociated with thekey. If the key does not exist or the value cannot be parsed as an enum, returns thedefvalue. -
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 thedefvalue. -
asList<
T> (String key, {List< T> ? def}) → List<T> -
Available on Map, provided by the MapFormatHelper extension
Retrieves the list of typeTassociated with thekey. If the key does not exist or the value cannot be parsed as a list, returns thedefvalue. -
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 typeTfrom 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 typeTfrom the map usingModelLessinstances 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 typeTtoKassociated with thekey. If the key does not exist or the value cannot be parsed as a map, returns thedefvalue. -
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 thedefvalue. -
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 thedefvalue. -
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 thedefvalue. -
removeNulls(
) → void -
Available on Map, provided by the MapFormatHelper extension
remove all null values from the map.