putDouble method
Method to set double in local storage
key
-> Key for key-value pair
isEncrypted
-> Flag whether to encrypt or not
val
-> Value for key-value pair
Implementation
Future<void> putDouble(String key, double val, {bool isEncrypted = false}) async {
_assetFunction(isEncrypted);
if (isEncrypted) {
if (Platform.isAndroid) {
_secureStorage?.write(key: key, value: val.toString());
} else if (Platform.isIOS) {
if (await _isMasterKeyAvailable() && _areSubKeysAvailable()) {
final keys = await _getEncrypterKeys();
final algorithm = _getAlgorithm();
final encryptedKey = await algorithm.encrypt(key.codeUnits,
secretKey:
SecretKey(keys.first[SuperSecureSharedPref.keyForKey]!),
nonce: keys.first[SuperSecureSharedPref.ivForKey]);
final encryptedValue = await algorithm.encrypt(
val.toString().codeUnits,
secretKey: SecretKey(keys.last[SuperSecureSharedPref.keyForKey]!),
nonce: keys.last[SuperSecureSharedPref.ivForKey]);
_sharedPreferences.setString(encryptedKey.cipherText.toString(),
encryptedValue.cipherText.toString());
} else {
if (await _isMasterKeyAvailable() &&
_areSubKeysAvailable() == false) {
await _deleteMasterKey();
}
var masterKey = await _createMasterKey();
await _saveMasterKeyToKeychain(masterKey);
await _generateAndSaveKeyAndValueSubKeys(
await _getMasterKeyFromKeyChain());
putDouble(key, val, isEncrypted:isEncrypted);
}
} else {
throw PlatformException(
message: "Not Supported for ${Platform.operatingSystem} platform",
code: "501");
}
} else {
_sharedPreferences.setDouble(key, val);
}
}