From cf3d235fac5cda317d198bcbe529792ec694a7d0 Mon Sep 17 00:00:00 2001 From: w568w <1278297578@qq.com> Date: Tue, 26 Nov 2024 17:59:01 +0800 Subject: [PATCH] fix: incorrect detection of data migration status caused data to become invalid in some case --- lib/util/shared_preferences.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/util/shared_preferences.dart b/lib/util/shared_preferences.dart index 5082009a..c7915b1c 100644 --- a/lib/util/shared_preferences.dart +++ b/lib/util/shared_preferences.dart @@ -101,7 +101,14 @@ class XSharedPreferences { // Proxy methods for [EncryptedSharedPreferences] - Future clear() => _preferences.clear(); + Future clear() async { + bool success = await _preferences.clear(); + if (success) { + // mark the data as migrated after clearing. Or the data written after clearing will be re-migrated. + await _instance!.setBool(KEY_MIGRATED, true); + } + return success; + } Future remove(String key) => _preferences.remove(key);