Skip to content
pubscout

streaming_shared_preferences

2.0.0, released 6 years ago by iiro.dev

A stream-based reactive wrapper over shared_preferences for key-value storage.

WASM-ready
$ flutter pub add streaming_shared_preferences
Source repository

What it does

Wraps regular shared_preferences to provide Streams for every stored key, allowing reactive listening of value changes. It also supplies a PreferenceBuilder widget to sync UI components seamlessly with persisted preferences.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to reactively listen to changes in shared_preferences across your Flutter app.
  • You prefer simple key-value local storage without heavy SQL setup.

Skip it when

  • You need complex relational querying, indexing, or encryption.
  • You are already using an all-in-one state management and persistence solution that doesn't use shared_preferences.

Strengths

  • Easy migration from regular shared_preferences.
  • Comes with a convenient PreferenceBuilder widget to reduce boilerplate.
  • Supports custom objects and serialization via JsonAdapter.

Weaknesses

  • Change detection only works on the Dart side through this package's API.
  • Limited to key-value storage use cases.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2

Call WidgetsFlutterBinding.ensureInitialized() before obtaining the StreamingSharedPreferences instance.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final preferences = await StreamingSharedPreferences.instance;
  Preference<int> counter = preferences.getInt('counter', defaultValue: 0);
  counter.listen((value) => print(value));
  counter.setValue(1);
}

Alternatives

Packages that do the same job and could replace streaming_shared_preferences.

  • hive_ce

    If you need a faster, pure Dart NoSQL key-value database with built-in reactive boxes.

Works with

Packages commonly used together with streaming_shared_preferences: ones it builds on, ones built on it, and its own family.