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 the key. If the key does not exist, returns the def value.
asBool(String key, {dynamic def = false}) bool

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

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>

Available on Map, provided by the MapFormatHelper extension

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>

Available on Map, provided by the MapFormatHelper extension

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>

Available on Map, provided by the MapFormatHelper extension

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>

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

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

Available on Map, provided by the MapFormatHelper extension

Retrieves the string value associated with the key. If the key does not exist, returns the def value.
removeNulls() → void

Available on Map, provided by the MapFormatHelper extension

remove all null values from the map.