Perfect for developers prioritizing security, Encrypted Shared Preferences integrates effortlessly into your projects, offering peace of mind and enhancing data privacy. Safeguard your app's data with this essential encryption solution
Apache License 2.0
12
stars
2
forks
source link
Proposal: Align API with shared_preferences for Hot-Swap Compatibility #9
The encrypted-shared-preferences package offers similar functionality to Flutter's shared_preferences but lacks full API compatibility, making it challenging to swap them seamlessly. Aligning encrypted-shared-preferences with the shared_preferences API would allow developers to use it as a direct replacement without breaking changes.
API Inconsistencies Identified:
Missing Methods:
containsKey
getAll
getKeys
getStringList
setStringList
Method Signature Differences:
clear: Should accept {Set<String>? allowList}
getBoolean: Should be renamed to getBool and return a Future
getDouble: Should return a Future
getInt: Should return a Future
getString: Should return a Future
setBoolean: Should be renamed to setBool
Proposal
API Compatibility:
Implement the missing methods and adapt existing ones to ensure API consistency with shared_preferences.
Ensure the methods return the same data types (Future) where applicable.
Adopt SharedPreferencesAsync and SharedPreferencesWithCache Approach:
Implement both SharedPreferencesAsync and SharedPreferencesWithCache patterns to provide caching and asynchronous behavior, similar to shared_preferences.
Consider deprecating any synchronous methods to maintain consistency with SharedPreferencesAsync.
Default Values:
Instead of providing default values, methods should return null, allowing users to handle them with the null-aware operator (??). This approach aligns with modern Dart practices and simplifies integration.
Consistent Asynchronous Behavior:
Currently, get methods are synchronous, while set methods are asynchronous. It is preferable for all methods to be asynchronous (Future) for consistency and to handle encrypted operations correctly.
Why This Is Important
This alignment would enable developers to use encrypted-shared-preferences as a drop-in, encrypted alternative to shared_preferences without requiring additional wrappers or significant code changes.
By offering a similar API and adopting the SharedPreferencesAsync approach, this package would become a highly valuable, secure storage solution in the Flutter ecosystem.
Side Note
At the moment, we're forced to write a wrapper around encrypted-shared-preferences to implement SharedPreferencesAsync ourselves. This change would eliminate the need for custom wrappers and simplify secure data management in Flutter applications.
Overview
The
encrypted-shared-preferences
package offers similar functionality to Flutter'sshared_preferences
but lacks full API compatibility, making it challenging to swap them seamlessly. Aligningencrypted-shared-preferences
with theshared_preferences
API would allow developers to use it as a direct replacement without breaking changes.API Inconsistencies Identified:
Missing Methods:
containsKey
getAll
getKeys
getStringList
setStringList
Method Signature Differences:
clear
: Should accept{Set<String>? allowList}
getBoolean
: Should be renamed togetBool
and return aFuture
getDouble
: Should return aFuture
getInt
: Should return aFuture
getString
: Should return aFuture
setBoolean
: Should be renamed tosetBool
Proposal
API Compatibility:
shared_preferences
.Future
) where applicable.Adopt
SharedPreferencesAsync
andSharedPreferencesWithCache
Approach:SharedPreferencesAsync
andSharedPreferencesWithCache
patterns to provide caching and asynchronous behavior, similar toshared_preferences
.SharedPreferencesAsync
.Default Values:
null
, allowing users to handle them with the null-aware operator (??
). This approach aligns with modern Dart practices and simplifies integration.Consistent Asynchronous Behavior:
get
methods are synchronous, whileset
methods are asynchronous. It is preferable for all methods to be asynchronous (Future
) for consistency and to handle encrypted operations correctly.Why This Is Important
encrypted-shared-preferences
as a drop-in, encrypted alternative toshared_preferences
without requiring additional wrappers or significant code changes.SharedPreferencesAsync
approach, this package would become a highly valuable, secure storage solution in the Flutter ecosystem.Side Note
At the moment, we're forced to write a wrapper around
encrypted-shared-preferences
to implementSharedPreferencesAsync
ourselves. This change would eliminate the need for custom wrappers and simplify secure data management in Flutter applications.Thank you for considering this request!