Skip to content

tmaihoff/shared_preferences_storage

Repository files navigation

Shared Preferences Storage

style: very good analysis Powered by Mason License: BSD-3-Clause

A Storage implementation for HydratedBloc and HydratedCubit that uses shared_preferences to persist state.

When to Use

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.

Installation 💻

❗ 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.git

Or install via command line:

flutter pub add shared_preferences_storage --git-url=https://github.com/tmaihoff/shared_preferences_storage.git

API

SharedPreferencesStorage

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.

Running Tests 🧪

Install the very_good_cli:

dart pub global activate very_good_cli

Run all unit tests:

very_good test --coverage

Related Packages

  • hydrated_bloc - Bloc state management with automatic persistence
  • bloc - State management library for Dart
  • shared_preferences - Platform-specific persistent storage for simple data

License

BSD-3-Clause. See LICENSE for details.

About

Storage implementation using shared_preferences to be used in hydrated_bloc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages