convertJsObjectToMap<K, V> static method
Convert a js map that is a basic js object to a Map with key K
and
value V
.
Set the keyConverter
and/ or the valueConverter
to change the behaviour
on how the keys and/ or values should be converted inside the resulting map.
By default if they are not set the castConverter will be used.
Implementation
static Map<K, V> convertJsObjectToMap<K, V>(final Object map,
{final K Function(Object)? keyConverter,
final V Function(Object)? valueConverter}) {
final List<K> keys = WebBluetoothConverters.convertJSObjectToList(
_JSUtil.callMethod(map, "keys", []), keyConverter);
final Map<K, V> converted = {};
for (final item in keys) {
converted[item] = valueConverter != null
? valueConverter.call(_JSUtil.callMethod(map, "get", [item]))
: castConverter<V>(_JSUtil.callMethod(map, "get", [item]));
}
return converted;
}