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 the def 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 the def 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 the def 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 the key. If the key does not exist or the value cannot be parsed as an enum, returns the def 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 the def value.
asList<T>(String key, {List<T>? def}) List<T>
Retrieves the list of type T associated with the key. If the key does not exist or the value cannot be parsed as a list, returns the def 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 using ModelLess 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 to K associated with the key. If the key does not exist or the value cannot be parsed as a map, returns the def 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 the def 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 the def value.
asString(String key, {String def = ''}) String
Retrieves the string value associated with the key. If the key does not exist, returns the def value.