getInt method
Method to get String from local storage
key
-> Key which you have provided while setting
isEncrypted
-> Flag which you have provided while encrypting
Implementation
Future<int?> getInt(String key, {bool isEncrypted = false}) async {
_assetFunction(isEncrypted);
if (isEncrypted) {
if (Platform.isAndroid) {
return int.tryParse(await _secureStorage?.read(key: key) ?? "0");
} else if (Platform.isIOS) {
if (await _isMasterKeyAvailable()) {
print("_isMasterKeyAvailable true}");
var keys = await _getEncrypterKeys();
print("_getEncrypterKeys $keys}");
for (var value in _sharedPreferences.getKeys()) {
print("keys $value}");
if (_getIntListFromString(value).length == 16) {
String decoded = await _decrypt(value, keys.first);
if (decoded == key) {
print("decoded $decoded}");
return int.tryParse(await _decrypt(
_sharedPreferences.getString(value) ?? "", keys.last));
}
}
}
} else {
throw Exception(
"Failed to get data something is not correct, please report issue on github");
}
} else {
throw PlatformException(
message: "Not Supported for ${Platform.operatingSystem} platform",
code: "501");
}
} else {
return _sharedPreferences.getInt(key);
}
return 0;
}