put method Null safety

  1. @override
Future<bool> put(
  1. AtKey atKey,
  2. dynamic value,
  3. {bool isDedicated = false}
)
override

Updates value of AtKey.key is if it is already present. Otherwise creates a new key. Set AtKey.sharedWith if the key has to be shared with another atSign. Set AtKey.metadata.isBinary if you are updating binary value e.g image,file. By default namespace that is used to create the AtClient instance will be appended to the key. phone@alice will be saved as phone.persona@alice where 'persona' is the namespace. If you want to save by ignoring the namespace set AtKey.metadata.namespaceAware to false. Additional metadata can be set using AtKey.metadata isDedicated need to be set to true to create a dedicated connection

update:phone@alice +1 999 9999
  var key = AtKey()..key='phone'
  put(key,'+1 999 9999');
update:public:phone@alice +1 999 9999
  var metaData = Metadata()..isPublic=true;
  var key = AtKey()..key='phone'
            ..metadata=metaData
  put(key,'+1 999 9999');
update:@bob:phone@alice +1 999 9999
  var metaData = Metadata()..sharedWith='@bob';
   var key = AtKey()..key='phone'
                  ..metadata=metaData
  put(key,'+1 999 9999');
update:@alice:phone.persona@alice +1 999 9999
  var key = AtKey()..key='phone'
            ..sharedWith='@alice'
  put(key, '+1 999 9999');
update:@alice:phone@alice +1 999 9999
  var metaData = Metadata()..namespaceAware=false
  var key = AtKey()..key='phone'
           sharedWith='@alice'
  put(key, '+1 999 9999');
update:@bob:phone.persona@alice +1 999 9999
  var key = AtKey()..key='phone'
            sharedWith='@bob'
   put(key, '+1 999 9999');

Starting version 3.0.0 isDedicated is deprecated Throws AtValueException if invalid value type is found

Throws AtKeyException if invalid key or metadata is found

Throws AtEncryptionException if encryption process fails

Throws SelfKeyNotFoundException if self encryption key is not found

Throws AtPrivateKeyNotFoundException if encryption private key is not found

Throws AtPublicKeyNotFoundException if encryption public key is not found

Implementation

@override
Future<bool> put(AtKey atKey, dynamic value,
    {bool isDedicated = false}) async {
  // If the value is neither String nor List<int> throw exception
  if (value is! String && value is! List<int>) {
    throw AtValueException(
        'Invalid value type found ${value.runtimeType}. Expected String or List<int>');
  }
  AtResponse atResponse = AtResponse();
  if (value is String) {
    atResponse = await putText(atKey, value);
  }
  if (value is List<int>) {
    atResponse = await putBinary(atKey, value);
  }
  return atResponse.response.isNotEmpty;
}