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