Skip to content

Commit

Permalink
fix(native_storage): Clear local storage on macOS/iOS
Browse files Browse the repository at this point in the history
The iteration logic was causing a crash in the CLI. Also prefers `prefix` over `scope` for deletion inclusion.
  • Loading branch information
dnys1 committed Apr 7, 2024
1 parent e3d259f commit c1471f0
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/native/storage/lib/src/local/local_storage_darwin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit c1471f0

Please sign in to comment.