enhanced_preferences 0.2.0 copy "enhanced_preferences: ^0.2.0" to clipboard
enhanced_preferences: ^0.2.0 copied to clipboard

Wraps platform-specific persistent storage for simple data.

Enhanced shared preferences plugin #

Wraps platform-specific persistent storage for simple data. Supported data types are String, int, double and bool.

Platform Storage Keystore
Android DataStore Preferences Android Keystore
iOS NSUserDefaults Keychain
Web localStorage NOT SUPPORTED

Usage #

Write data #

final EnhancedPreferences prefs = EnhancedPreferences();

// Specify options.
final EnhancedPreferencesOptions options = EnhancedPreferencesOptions();

// Save an String value to 'hello' key.
await prefs.setString('hello', 'World', options);
// Save an integer value to 'counter' key.
await prefs.setInt('counter', 10, options);
// Save an double value to 'rate' key.
await prefs.setDouble('rate', 0.9, options);
// Save an boolean value to 'isActive' key.
await prefs.setBool('isActive', true, options);

Read data #

final EnhancedPreferences prefs = EnhancedPreferences();

// Specify options.
final EnhancedPreferencesOptions options = EnhancedPreferencesOptions();

// Try reading data from the 'Hello' key.
final String? hello = await prefs.getString('hello', options);
// Try reading data from the 'counter' key.
final int? counter = await prefs.getInt('counter', options);
// Try reading data from the 'rate' key.
final double? rate = await prefs.getDouble('rate', options);
// Try reading data from the 'isActive' key.
final bool? isActive = await prefs.getBool('isActive', options);

Remove an entry #

// Remove data for the 'hello' key.
await prefs.remove('hello');

Options #

Option Type Detail Default
enableCache bool Whether to enable cache. true
enableEncryption bool Whether to enable encryption. It is not supported on the web platform because sensitive data must be stored on the server for security reasons and it is unable to manage keys safely in browsers. false

Errors #

Error code Detail
INVALID_ARGUMENT Invalid arguments such as the key is blank.
REFERENCE_ERROR Failed to obtain the value for key.
ILLEGAL_ACCESS Failed to encrypt / decrypt the value for key.
UNKNOWN_ERROR Other causes.

Buy Me A Coffee

0
likes
0
points
126
downloads

Publisher

unverified uploader

Weekly Downloads

Wraps platform-specific persistent storage for simple data.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on enhanced_preferences

Packages that implement enhanced_preferences