【发布时间】:2021-07-16 02:07:47
【问题描述】:
在这个问题上需要一些帮助,我已经尝试了所有方法,但真的不知道如何解决这个问题。
我正在根据 Hive documentation 应用代码,以使用secure_storage 进行加密存储和密钥存储。我选择使用具有空安全性的 dart 2.12 但这似乎是不可能的。我真的不知道真正的问题在哪里。
final FlutterSecureStorage secureStorage = const FlutterSecureStorage();
var containsEncryptionKey = await secureStorage.containsKey(key: 'key');
if (!containsEncryptionKey) {
var key = Hive.generateSecureKey();
await secureStorage.write(key: 'key', value: base64UrlEncode(key));
}
var encryptionKey = base64Url.decode(await secureStorage.read(key: 'key'));
var encryptedBox =
await Hive.openBox<Sale>(kSalesBox, encryptionCipher: HiveAesCipher(encryptionKey));
上面的问题突出显示为:await secureStorage.read(key: 'key')
我已经尝试了所有方法,但我无法理解 IDE 想要什么,该消息在此应用程序中没有意义。
错误信息:
Decrypts and returns the value for the given [key] or null if [key] is not in the storage.
[key] shouldn't be null. [iOptions] optional iOS options [aOptions] optional Android options [lOptions] optional Linux options Can throw a [PlatformException].
The argument type 'String?' can't be assigned to the parameter type 'String'.
但密钥不会为空!这就是“if”检查的用途......
【问题讨论】: