juice_storage library
Local storage, caching, and secure storage for the Juice framework.
Provides a unified BLoC-based API for multiple storage backends:
- Hive - structured local key-value with boxes
- SharedPreferences - simple key-value storage
- SQLite - relational database storage
- Secure Storage - encrypted storage for secrets
Quick Start
// Create the bloc with configuration
final storage = StorageBloc(config: StorageConfig(
hiveBoxesToOpen: ['cache', 'settings'],
prefsKeyPrefix: 'myapp_',
));
// Use helper methods
await storage.prefsWrite('theme', 'dark');
final theme = await storage.prefsRead<String>('theme');
// With TTL
await storage.hiveWrite('cache', 'data', myData, ttl: Duration(hours: 1));
// Secure storage for secrets
await storage.secureWrite('token', authToken);
Rebuild Groups
storage:init- Initialization statusstorage:hive:{boxName}- Per-box changesstorage:prefs- SharedPreferences changesstorage:sqlite:{tableName}- Per-table changesstorage:secure- Secure storage changesstorage:cache- Cache metadata changes
Classes
- BoxInfo
- Information about an open Hive box.
- CacheCleanupEvent
- Clean up expired cache entries.
- CacheIndex
- Index for managing cache TTL metadata.
- CacheMetadata
- Metadata for cached items with TTL support.
- CacheMetadataAdapter
- CacheStats
- Statistics about the cache system.
- ClearAllEvent
- Clear all storage (logout scenario).
- ClearAllOptions
- Options for ClearAllEvent.
- HiveCloseBoxEvent
- Close a Hive box.
- HiveDeleteEvent
- Delete a value from Hive.
- HiveKeysEvent
- Get all keys from a Hive box.
- HiveOpenBoxEvent
- Open a Hive box.
- HiveReadEvent
- Read a value from Hive.
- HiveWriteEvent
- Write a value to Hive.
- InitializeStorageEvent
- Initialize the storage system.
-
OperationResult<
TResult, TState extends BlocState> - The outcome of ResultEventOps.sendAndWaitResult: the terminal status the use case emitted for the event, and the value it completed the event with (null unless isSuccess).
- PrefsDeleteEvent
- Delete a value from SharedPreferences.
- PrefsReadEvent
- Read a value from SharedPreferences.
- PrefsWriteEvent
- Write a value to SharedPreferences.
-
ResultEvent<
TResult> - Base class for events that return typed results.
- SecureDeleteAllEvent
- Delete all secure storage.
- SecureDeleteEvent
- Delete a value from secure storage.
- SecureReadEvent
- Read a value from secure storage.
- SecureWriteEvent
- Write a value to secure storage.
- SqliteDeleteEvent
- Delete rows from SQLite.
- SqliteInsertEvent
- Insert a row into SQLite.
- SqliteQueryEvent
- Execute a SQLite query.
- SqliteRawEvent
- Execute raw SQL.
- SqliteUpdateEvent
- Update rows in SQLite.
- StorageBackendStatus
- Status of all storage backends.
- StorageBloc
- BLoC for managing local storage operations.
- StorageConfig
- Configuration for the StorageBloc.
- StorageError
- Error information stored in state.
- StorageKeys
- Canonical storage key builder for TTL metadata and debugging.
-
StorageResultEvent<
TResult> - Base class for storage events that return typed results.
- StorageState
- State for the StorageBloc.
- TableInfo
- Information about a SQLite table.
Enums
- BackendState
- State of a storage backend.
- StorageErrorType
- Error types for storage operations.
Extensions
-
ResultEventOps
on JuiceBloc<
TState> - Send a ResultEvent and await its outcome.
Exceptions / Errors
- BackendNotAvailableException
- Exception thrown when a backend is not available.
- BoxNotOpenException
- Exception thrown when a Hive box is not open.
- EncryptionException
- Exception thrown when encryption/decryption fails.
- KeyNotFoundException
- Exception thrown when a key is not found.
- PlatformNotSupportedException
- Exception thrown when a platform feature is not supported.
- SerializationException
- Exception thrown when serialization fails.
- SqliteException
- Exception thrown for SQLite errors.
- StorageException
- Base exception for storage operations.
- StorageNotInitializedException
- Exception thrown when storage is not initialized.
- StoragePermissionDeniedException
- Exception thrown when permission is denied.
- StorageTypeException
- Exception thrown when a type error occurs during read/write.