A Storage implementation for HydratedBloc and HydratedCubit that uses shared_preferences to persist state.
Use this package when you need bloc/cubit state to persist across app reinstalls. This is useful for:
- Theme mode preferences
- Onboarding completion flags
- "Rate this app" dialog states
- User preferences and settings
Since shared_preferences uses platform-specific persistent storage (NSUserDefaults on iOS/macOS, SharedPreferences on Android, etc.), state may be preserved across app reinstalls depending on the platform's backup behavior.
❗ In order to start using Shared Preferences Storage you must have the Flutter SDK installed on your machine.
Note: This package is not published to pub.dev. Install directly from GitHub.
Add shared_preferences_storage to your pubspec.yaml:
dependencies:
shared_preferences_storage:
git:
url: https://github.com/tmaihoff/shared_preferences_storage.gitOr install via command line:
flutter pub add shared_preferences_storage --git-url=https://github.com/tmaihoff/shared_preferences_storage.git| Method | Description |
|---|---|
build() |
Returns a singleton instance of SharedPreferencesStorage. |
read(String key) |
Reads a value from storage. |
write(String key, dynamic value) |
Writes a value to storage. |
delete(String key) |
Deletes a value from storage. |
clear() |
Clears all values from storage. |
close() |
Closes the storage instance. |
Install the very_good_cli:
dart pub global activate very_good_cliRun all unit tests:
very_good test --coverage- hydrated_bloc - Bloc state management with automatic persistence
- bloc - State management library for Dart
- shared_preferences - Platform-specific persistent storage for simple data
BSD-3-Clause. See LICENSE for details.