-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#5210Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: shared_preferencesPlugin to read and write Shared PreferencesPlugin to read and write Shared Preferencespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Use case
As per the current implementation, the shared_preferences plugin allows setting a custom prefix using setPrefix before any instances are instantiated. However, if setPrefix is called after getInstance, it results in a failure, even if the new prefix matches the previously set one. This poses challenges in complex applications where multiple independent packages might attempt to set or check the prefix independently, leading to potential conflicts and runtime exceptions.
Proposal
- Introduce a
hasInstance()method: This method would allow developers to check if an instance of SharedPreferences has already been created, which helps in deciding whether it’s safe to callsetPrefix. - Modify
setPrefix()to allow idempotent operations: IfsetPrefixis called with a prefix that matches the already set prefix, the method should not fail. This adjustment would make the prefix setting idempotent and safer in environments where multiple checks might occur.
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: shared_preferencesPlugin to read and write Shared PreferencesPlugin to read and write Shared Preferencespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team