asMap<E> method

E asMap<E>(
  1. String key, {
  2. BlockchainUtilsException? error,
})

Implementation

E asMap<E>(String key, {BlockchainUtilsException? error}) {
  if (_map is! E) {
    throw const DartSuiPluginException(
        'Invalid map casting. only use `asMap` method for casting Map<String,dynamic>.');
  }
  final Map? value = as(key);
  if (value == null) {
    if (null is E) {
      return null as E;
    }
    throw error ??
        DartSuiPluginException('Key not found.',
            details: {'key': key, 'data': this});
  }
  try {
    return value.cast<String, dynamic>() as E;
  } on TypeError {
    throw error ??
        DartSuiPluginException('Incorrect value.', details: {
          'key': key,
          'expected': '$E',
          'value': value.runtimeType,
          'data': this
        });
  }
}