Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## NEXT

* Fixes getting all preferences when suite name is used.
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 2.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class RunnerTests: XCTestCase {
// Async system tests.

let emptyOptions = SharedPreferencesPigeonOptions()
let optionsWithSuiteName = SharedPreferencesPigeonOptions(suiteName: "group.example.sharedPreferencesFoundationExample")

func testAsyncSetAndGet() throws {
let plugin = SharedPreferencesPlugin()
Expand Down Expand Up @@ -153,6 +154,19 @@ class RunnerTests: XCTestCase {
XCTAssertEqual(storedValues["aStringList"] as? [String], ["hello", "world"])

}

func testAsyncGetAllWithAndWithoutSuiteName() throws {
let plugin = SharedPreferencesPlugin()

try plugin.set(key: "aKey", value: "hello world", options: emptyOptions)
try plugin.set(key: "aKeySuite", value: "hello world with suite", options: optionsWithSuiteName)

let storedValues = try plugin.getAll(allowList: nil, options: emptyOptions)
XCTAssertEqual(storedValues["aKey"] as? String, "hello world")

let storedValuesWithGroup = try plugin.getAll(allowList: nil, options: optionsWithSuiteName)
XCTAssertEqual(storedValuesWithGroup["aKeySuite"] as? String, "hello world with suite")
}

func testAsyncGetAllWithAllowList() throws {
let plugin = SharedPreferencesPlugin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
var filteredPrefs: [String: Any] = [:]
var compatiblePrefs: [String: Any] = [:]
let allowSet = allowList.map { Set($0) }
if let appDomain = Bundle.main.bundleIdentifier,

// Since `getUserDefaults` is initialized with the suite name, it seems redundant to call
// `persistentDomain` with the suite name again. However, it is necessary because
// `dictionaryRepresentation` returns keys from the global domain.
// Also, Apple's docs on `persistentDomain` are incorrect,
// see: https://github.com/feedback-assistant/reports/issues/165
if let appDomain = options.suiteName ?? Bundle.main.bundleIdentifier,
let prefs = try getUserDefaults(options: options).persistentDomain(forName: appDomain)
{
if let allowSet = allowSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_foundation
description: iOS and macOS implementation of the shared_preferences plugin.
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.5.0
version: 2.5.1

environment:
sdk: ^3.3.0
Expand Down