Skip to content
pubscout

typed_preferences

0.2.0, released 4 years ago by yakov.codes

A type‑safe wrapper around SharedPreferences with observers and DAO support.

WASM-ready
$ flutter pub add typed_preferences
Source repository

What it does

Provides a typed API for reading and writing SharedPreferences values, automatically prefixes keys, and caches entries. Adds observer hooks to react to preference changes and lets you define DAOs for schema‑like access.

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

Use it when

  • You want compile‑time type safety for preference keys
  • You need to react to preference changes via observers
  • You prefer a DAO‑style, declarative definition of stored values

Skip it when

  • You only need a few simple key‑value pairs and want minimal overhead
  • You require encrypted or secure storage out of the box

Strengths

  • Type‑safe get/set operations
  • Observer callbacks for change tracking
  • DAO pattern simplifies schema definition
  • Works on all Flutter platforms

Weaknesses

  • Adds an extra abstraction layer over SharedPreferences
  • Breaking API change in 0.2.0 (generics must extend Object)
  • Limited to SharedPreferences; no built‑in encryption

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2
final prefs = await SharedPreferences.getInstance();
final driver = PreferencesDriver(sharedPreferences: prefs);
class UserDao extends TypedPreferencesDao {
  UserDao(super.driver);
  PreferencesEntry<String> get name => stringEntry('name');
  PreferencesEntry<int> get age => intEntry('age');
}
final userDao = UserDao(driver);
await userDao.name.set('Alice');
int age = await userDao.age.get();

Alternatives

Packages that do the same job and could replace typed_preferences.

Works with

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