invokeMapMethod<K, V> method Null safety

Future<Map<K, V>?> invokeMapMethod<K, V>(
  1. String method,
  2. [dynamic arguments]

An implementation of invokeMethod that can return typed maps.

Dart generics are reified, meaning that an untyped Map<dynamic, dynamic> cannot masquerade as a Map<K, V>. Since invokeMethod can only return dynamic maps, we instead create a new typed map using Map.cast.

See also:


Future<Map<K, V>?> invokeMapMethod<K, V>(String method, [ dynamic arguments ]) async {
  final Map<dynamic, dynamic>? result = await invokeMethod<Map<dynamic, dynamic>>(method, arguments);
  return result?.cast<K, V>();