From 099f6faf4d5fdcd7f486f171f315974a61c62686 Mon Sep 17 00:00:00 2001 From: Abdelrahman Saed Date: Wed, 29 Jul 2026 02:07:38 +0300 Subject: [PATCH 1/2] Document return values of set and remove methods in SharedPreferences Add dartdoc to setBool, setInt, setDouble, setString, setStringList, and remove explaining the meaning of their return values, using the wording suggested by @stuartmorgan-g in the closed PR #7198. Fixes flutter/flutter#146070 --- .../lib/src/shared_preferences_legacy.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/shared_preferences/shared_preferences/lib/src/shared_preferences_legacy.dart b/packages/shared_preferences/shared_preferences/lib/src/shared_preferences_legacy.dart index d7007c5f041e..3c428d4ef2fa 100644 --- a/packages/shared_preferences/shared_preferences/lib/src/shared_preferences_legacy.dart +++ b/packages/shared_preferences/shared_preferences/lib/src/shared_preferences_legacy.dart @@ -139,14 +139,29 @@ class SharedPreferences { } /// Saves a boolean [value] to persistent storage in the background. + /// + /// Returns `false` if the platform implementation can definitively determine + /// that storing the preference failed. A return value of `true` indicates + /// either that the value was written successfully, or that the underlying + /// platform API does not report success or failure. Future setBool(String key, bool value) => _setValue('Bool', key, value); /// Saves an integer [value] to persistent storage in the background. + /// + /// Returns `false` if the platform implementation can definitively determine + /// that storing the preference failed. A return value of `true` indicates + /// either that the value was written successfully, or that the underlying + /// platform API does not report success or failure. Future setInt(String key, int value) => _setValue('Int', key, value); /// Saves a double [value] to persistent storage in the background. /// /// Android doesn't support storing doubles, so it will be stored as a float. + /// + /// Returns `false` if the platform implementation can definitively determine + /// that storing the preference failed. A return value of `true` indicates + /// either that the value was written successfully, or that the underlying + /// platform API does not report success or failure. Future setDouble(String key, double value) => _setValue('Double', key, value); /// Saves a string [value] to persistent storage in the background. @@ -157,12 +172,27 @@ class SharedPreferences { /// - 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu' /// - 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy' /// - 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu' + /// + /// Returns `false` if the platform implementation can definitively determine + /// that storing the preference failed. A return value of `true` indicates + /// either that the value was written successfully, or that the underlying + /// platform API does not report success or failure. Future setString(String key, String value) => _setValue('String', key, value); /// Saves a list of strings [value] to persistent storage in the background. + /// + /// Returns `false` if the platform implementation can definitively determine + /// that storing the preference failed. A return value of `true` indicates + /// either that the value was written successfully, or that the underlying + /// platform API does not report success or failure. Future setStringList(String key, List value) => _setValue('StringList', key, value); /// Removes an entry from persistent storage. + /// + /// Returns `false` if the platform implementation can definitively determine + /// that removing the preference failed. A return value of `true` indicates + /// either that the value was removed successfully, or that the underlying + /// platform API does not report success or failure. Future remove(String key) { final prefixedKey = '$_prefix$key'; _preferenceCache.remove(key); From 3223ba71ea6a706738f4c9bc01aa9d84e11f6b75 Mon Sep 17 00:00:00 2001 From: Abdelrahman Saed Date: Wed, 29 Jul 2026 16:45:39 +0300 Subject: [PATCH 2/2] Add CHANGELOG entry under NEXT --- packages/shared_preferences/shared_preferences/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/shared_preferences/shared_preferences/CHANGELOG.md b/packages/shared_preferences/shared_preferences/CHANGELOG.md index 915fbb4d4e37..4c5780feb356 100644 --- a/packages/shared_preferences/shared_preferences/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences/CHANGELOG.md @@ -1,5 +1,6 @@ ## NEXT +* Documents the meaning of the return values of the set and remove methods. * Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. ## 2.5.5