From c1471f021cdb92d1a22140946ce2adcacba69d6c Mon Sep 17 00:00:00 2001 From: Dillon Nys Date: Fri, 5 Apr 2024 09:52:19 -0700 Subject: [PATCH] fix(native_storage): Clear local storage on macOS/iOS The iteration logic was causing a crash in the CLI. Also prefers `prefix` over `scope` for deletion inclusion. --- .../lib/src/local/local_storage_darwin.dart | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/native/storage/lib/src/local/local_storage_darwin.dart b/packages/native/storage/lib/src/local/local_storage_darwin.dart index 1e592259..c3246de2 100644 --- a/packages/native/storage/lib/src/local/local_storage_darwin.dart +++ b/packages/native/storage/lib/src/local/local_storage_darwin.dart @@ -50,15 +50,11 @@ final class LocalStoragePlatformDarwin extends NativeLocalStoragePlatform { @override void clear() { - final allValues = _userDefaults.persistentDomainForName_( - darwin.nsString(namespace), - ); - if (allValues == null) { - return; - } - for (var i = 0; i < allValues.allKeys.count; i++) { - final key = NSString.castFrom(allValues.allKeys.objectAtIndex_(i)); - if (scope == null || key.toString().startsWith(scope!)) { + final allValues = _userDefaults.dictionaryRepresentation(); + final allKeys = allValues.allKeys; + for (var i = 0; i < allKeys.count; i++) { + final key = NSString.castFrom(allKeys.objectAtIndex_(i)); + if (scope == null || key.toString().startsWith(_prefix)) { _userDefaults.removeObjectForKey_(key); } }