A code generator that writes your preference management boilerplate for you. Define your settings once as a Dart class — get back a fully type-safe, storage-agnostic API tailored to your project.
- ✅ No typos. All storage keys are generated constants. Mistakes are caught at compile time, not runtime.
- ✅ Any storage backend. Works with
shared_preferences, Hive, secure storage, or anything else. The adapter contract is intentionally minimal. - ✅ Automatic serialization.
DateTime,Duration,Enum,Record, and custom classes viaPrefConverter— the generator handles conversion to and from primitives automatically. - ✅ Template-based naming. Method names are configured with readable
template strings (
'set{{Name}}','watch{{Name}}Stream') rather than opaque config objects. - ✅ Reactive UIs out of the box. The
.reactive()preset generatesStreams and wires upChangeNotifierautomatically. - ✅ Fine-grained control. Override any method name per entry, disable individual methods, mark fields read-only — all with a single annotation.
- Define a schema — write a private constructor listing your preferences and their defaults.
- Run the generator —
dart run build_runner build. - Use your class — the generator produces a tailored class with exactly the methods you configured.
| Package | Description |
|---|---|
preferences_generator |
The build_runner generator. Primary documentation lives here. |
preferences_annotation |
Annotations and interfaces (the runtime dependency). |
| Example | Description |
|---|---|
app_example |
A complete Flutter app with a reactive settings screen, ChangeNotifier, secure storage, and Color/custom-type serialization. |
console_example |
A CLI app demonstrating every supported type and annotation feature using the .exhaustive() preset. |
See MIGRATION.md for a step-by-step guide covering every breaking change in v3.0.0.
This is a Melos monorepo.
# One-time setup
dart pub global activate melos
melos bootstrap
# Common tasks
melos test # run all tests
melos generate # run build_runner across all packages
melos analyze # static analysisMIT — see the LICENSE file for details.