as<T> method

T as<T>(
  1. String key, {
  2. BlockchainUtilsException? error,
})

Implementation

T as<T>(String key, {BlockchainUtilsException? error}) {
  final value = this[key];
  if (value == null) {
    if (null is T) {
      return null as T;
    }
    throw error ??
        DartSuiPluginException('Key not found.',
            details: {'key': key, 'data': this});
  }
  try {
    return value as T;
  } on TypeError {
    throw error ??
        DartSuiPluginException('Incorrect value.', details: {
          'key': key,
          'expected': '$T',
          'value': value.runtimeType,
          'data': this
        });
  }
}