kv_preferences library
A library for managing key-value preferences using shared preferences. It provides a structured way to define and access preferences with type safety. It includes support for complex types, versioning, and migration.
Classes
-
KeyPreferences<
T> Preferences - Represents a typed key in a key-value preferences store.
- KeyPreferencesGroup Preferences
- Represents a group of preferences identified by a unique key. This class is used to categorize and organize preferences within a key-value store. Each group has a unique identifier, which is used to categorize preferences. The group key is used to categorize preferences, allowing for better organization and management of preferences.
- KeyPreferencesGroup$Store
- A concrete implementation of KeyPreferencesGroup for storing application-wide preferences.
- KeyValuePreferences Preferences
- An abstract interface for a type-safe key-value storage system.
- KeyValuePreferencesBase Preferences
- An abstract base class for a type-safe key-value storage system. This class provides the foundational structure for implementing key-value preferences with versioning and initialization capabilities.
- KeyValuePreferencesMigrator Preferences
- An abstract class for migrating key-value preferences stores. This class provides methods to migrate the store from one version to another, and to check if migration is needed based on the current store version.
- Implementation of KeyValuePreferences using SharedPreferences. This class provides a singleton instance for accessing shared preferences and supports initialization, reading, writing, and clearing preferences. It also supports migration of preferences using a KeyValuePreferencesMigrator.
- Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data.
- Provides a persistent store for simple data.
- Basic options for creating SharedPreferencesAsync classes.
- Provides a persistent store for simple data.
- Options necessary to create a SharedPreferencesWithCache.
Typedefs
-
ValuePreferencesParser<
T> = T? Function(dynamic json) -
A parser function that converts JSON data into a value of type
T.
Exceptions / Errors
- MigrationException Preferences
- An exception thrown when migration cannot be performed. This exception indicates that the current version of the store cannot be migrated to the target version.
- MigrationNotPassedException Preferences
- An exception thrown when a migration has not been passed. This exception indicates that the migration process was not completed successfully, and the store is still at the current version.
-
ValuePreferencesFailedToEncodeException<
T> Preferences - Exception thrown when a value cannot be encoded to JSON for storage. This typically occurs when the value is not serializable or does not match the expected format defined by the KeyPreferences parser.
-
ValuePreferencesParserException<
T> Preferences - Exception thrown when a value cannot be parsed from the store. /// This typically occurs when the stored value does not match the expected type or format defined by the KeyPreferences parser.