magicMap method

Map magicMap({
  1. Map defaultValue = const {},
})

Converts the value to a Map.

  • defaultValue: The value to return if the conversion fails or the value is null.

Implementation

Map magicMap({Map defaultValue = const {}}) {
  if (isNull) return defaultValue;
  if (this is Map) return this as Map;
  if (this is List) {
    Map<int, dynamic> resultMap = {};
    for (var i = 0; i < (this as List).length; i++) {
      resultMap[i] = (this as List)[i];
    }
    return resultMap;
  }
  return defaultValue;
}