getBool method
Method to get boolean from local storage
key
-> Key which you have provided while setting
isEncrypted
-> Flag which you have provided while encrypting
Implementation
Future<bool?> getBool(String key, {bool isEncrypted = false}) async {
_assetFunction(isEncrypted);
if (isEncrypted) {
if (Platform.isAndroid) {
String? result = await _secureStorage?.read(key: key);
return result?.parseBool();
} else if (Platform.isIOS) {
if (await _isMasterKeyAvailable()) {
var keys = await _getEncrypterKeys();
for (var value in _sharedPreferences.getKeys()) {
if (value.length >= 2 &&
_getIntListFromString(value).length == 16) {
String decoded = await _decrypt(value, keys.first);
if (decoded == key) {
String result = await _decrypt(
_sharedPreferences.getString(value) ?? "", keys.last);
return result.parseBool();
}
}
}
} 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.getBool(key);
}
return null;
}