From 69d35d95d7c938a8e2fda576d26709fa11740408 Mon Sep 17 00:00:00 2001 From: Santatra00 <39788594+Santatra00@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:35:06 +0300 Subject: [PATCH] Variable type does not match This is the "original" code final key = await secureStorage.read(key: 'key'); final encryptionKey = base64Url.decode(key!); print('Encryption key: $encryptionKey'); final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher: HiveAesCipher(encryptionKey)); 1- the variable encryptionKey is declared as final on top, so it could not be final 2- the variable encryptionKey is typed as String? so it does not match with the return of .decode() -> Uint8List 3- because of these, the example code does not work I propose this : encryptionKey = await secureStorage.read(key: 'key'); final key = base64Url.decode(encryptionKey!); print('Encryption key: $key'); final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher: HiveAesCipher(key)); --- advanced/encrypted_box.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/encrypted_box.md b/advanced/encrypted_box.md index 8b46f0f..4b75845 100644 --- a/advanced/encrypted_box.md +++ b/advanced/encrypted_box.md @@ -22,10 +22,10 @@ void main() async { value: base64UrlEncode(key), ); } - final key = await secureStorage.read(key: 'key'); - final encryptionKey = base64Url.decode(key!); - print('Encryption key: $encryptionKey'); - final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher: HiveAesCipher(encryptionKey)); + encryptionKey = await secureStorage.read(key: 'key'); + final key = base64Url.decode(encryptionKey!); + print('Encryption key: $key'); + final encryptedBox= await Hive.openBox('vaultBox', encryptionCipher: HiveAesCipher(key)); encryptedBox.put('secret', 'Hive is cool'); print(encryptedBox.get('secret')); }