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 -
Retrieves the value associated with the
key
. If the key does not exist, returns thedef
value. -
asBool(
String key, {dynamic def = false}) → bool -
Retrieves the boolean value associated with the
key
. 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 -
Retrieves the double value associated with the
key
. 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 -
Retrieves an enum value of type
T
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 -
Retrieves the integer value associated with the
key
. 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> -
Retrieves the list of type
T
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> -
Retrieves a list of models of type
T
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> -
Retrieves a list of models of type
T
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> -
Retrieves the map of type
T
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 -
Retrieves the numeric value associated with the
key
. 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 -
Retrieves a regular expression pattern from the map associated with the
key
. If the key does not exist or the value cannot be parsed as a regex, returns thedef
value. -
asString(
String key, {String def = ''}) → String -
Retrieves the string value associated with the
key
. If the key does not exist, returns thedef
value.