flutter_secure_storage
flutter_secure_storage copied to clipboard
App fails with: nlohmann::json_abi_v3_11_2::detail::type_error
We're affected by the libjson
replacement with https://github.com/nlohmann/json in this commit: https://github.com/mogol/flutter_secure_storage/commit/647a5d1035444959dc9c3034a78a13154493b2dc
Below code
final random = Random();
final intRandom = random.nextInt(100000000);
final secureStorage = SecureStorage();
await secureStorage.write(key: 'testKey', value: intRandom.toString());
final readInt = await secureStorage.read(key: 'testKey');
context.showSnackBar(message: "Generated: ${intRandom.toString()}; Read after save: ${readInt.toString()}");
crashes the app, with below error:
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
what(): [json.exception.type_error.307] cannot use erase() with null
We can't reproduce it on the machine that we compile the code on, however once we pass code to another machine, e.g. using Flathub format: https://github.com/flathub/io.kapsa.drive/blob/master/io.kapsa.drive.json#L252 we get this error.
Our solution was to revert this commit in our fork: https://github.com/Mino5531/flutter_secure_storage/compare/develop...tomekit:flutter_secure_storage:develop
and load it like this:
dependencies:
flutter_secure_storage:
git:
url: https://github.com/tomekit/flutter_secure_storage.git
ref: develop
path: flutter_secure_storage
dependency_overrides:
flutter_secure_storage_linux:
git:
url: https://github.com/tomekit/flutter_secure_storage.git
ref: develop
path: flutter_secure_storage_linux
Do you have an idea why this error may occur on some machines?
Out of curiosity what was the reason of moving away from libjsoncpp25
?
I am experiencing the same error:
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
what(): [json.exception.type_error.307] cannot use erase() with null
Lost connection to device.
I am using flutter_secure_storage: ^9.0.0
Also experiencing the same issue with the same error on version 9.0.0
Hi! I fix this problem like this
final data = await _flutterSecureStorage?.read(key: 'myKey');
if(data != null) {
await _flutterSecureStorage?.delete(key: 'myKey');
}
Hi! I fix this problem like this
final data = await _flutterSecureStorage?.read(key: 'myKey'); if(data != null) { await _flutterSecureStorage?.delete(key: 'myKey'); }
Thank you. That solved the problem for me.
Bear in mind that if you have multiple processes reading/updating this key simultaneously given other bugs like (https://github.com/mogol/flutter_secure_storage/issues/592) you might end up with inconsistent results.
Bear in mind that if you have multiple processes reading/updating this key simultaneously given other bugs like (#592) you might end up with inconsistent results.
thanks