From 75b049f9651284981ad902f6cfe8bb6e7f60e624 Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Tue, 20 Feb 2024 14:11:33 +0100 Subject: [PATCH] Ensured hive key errors are handeled correctly (cherry picked from commit 7110e626c0a12347a2b80c20295a604f1e11c76b) --- lib/app_setup.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/app_setup.dart b/lib/app_setup.dart index 8903fbab..4fa5bfb1 100644 --- a/lib/app_setup.dart +++ b/lib/app_setup.dart @@ -137,14 +137,22 @@ Future _hiveKey() async { var secureStorage = const FlutterSecureStorage( aOptions: AndroidOptions(encryptedSharedPreferences: true), ); - const nonEncSharedPrefSecureStorage = FlutterSecureStorage(); + const nonEncSharedPrefSecureStorage = FlutterSecureStorage( + aOptions: AndroidOptions(encryptedSharedPreferences: false), + ); Uint8List? encryptionKey; try { encryptionKey = await secureStorage.read(key: keyName).then((value) => value?.let(base64Decode)); } on PlatformException catch (e) { logger.e('Error while reading hive_key from secure storage', e); - encryptionKey = await nonEncSharedPrefSecureStorage.read(key: keyName).then((value) => value?.let(base64Decode)); + encryptionKey = await nonEncSharedPrefSecureStorage + .read(key: keyName) + .then((value) => value?.let(base64Decode)) + .onError((error, stackTrace) { + logger.e('Error while reading hive_key from non-encryptedSharedPreferences', error, stackTrace); + return null; + }); await nonEncSharedPrefSecureStorage.delete(key: keyName); await secureStorage.write( key: keyName,