No boilerplate. No repeated strings. No setup. Define your variables once, then get() and set() them anywhere with zero friction. prf makes local persistence faster, simpler, and easier to scale, with 20+ built-in types and a clean, type-safe API. Designed to fully replace raw use of SharedPreferences.
All supported types use efficient binary encoding under the hood for optimal performance and minimal storage footprint — no setup required. Just use Prf<T> with any listed type, and everything works seamlessly.
Why Use prf
Working with SharedPreferences often leads to:
Repeated string keys
Manual casting and null handling
Verbose async boilerplate
Scattered, hard-to-maintain logic
prf solves all of that with a one-line variable definition that’s type-safe, cached, and instantly usable throughout your app. No key management, no setup, no boilerplate, no .getString(...) everywhere.
What Sets prf Apart?
✅ Single definition — just one line to define, then reuse anywhere
✅ Type-safe — no casting, no runtime surprises
✅ Automatic caching — with Prf<T> for fast access
✅ Easy isolate safety — with .isolated
✅ Lazy initialization — no need to call SharedPreferences.getInstance() or anything.
✅ Supports more than just primitives — 20+ types, Enums & JSON
✅ Built for testing — easily reset, override, or mock storage
✅ Cleaner codebase — no more scattered prefs.get...() or typo-prone string keys
All supported types use efficient binary encoding under the hood for optimal performance and minimal storage footprint — no setup required. Just use Prf<T> and everything works seamlessly.
🔧 Specialized Types - Enums & JSON
For enums and custom models, use the built-in factory helpers:
Prf.enumerated<T>() → enum value
Prf.enumeratedList<T>() → list of enum values
Prf.json<T>() → custom model object
Prf.jsonList<T>() → list of custom model objects
Prf.cast<T, TCast>() → custom behavior
🛰 Need Isolate Safety?
Every Prf object supports the .isolated getter — no matter the type (enums, bytes, JSON, lists, etc).
It returns a PrfIso that works safely across isolates (no caching, always reads from disk).
These are practically the same:
final safeUser = Prf<String>('username').isolated; // Samefinal safeUser = PrfIso<String>('username'); // Same
🎯 Example: Persisting an Enum
Define your enum:
enumAppTheme { light, dark, system }
Store it using Prf.enumerated (cached) or PrfIso.enumerated (isolate-safe):
final appTheme = Prf.enumerated<AppTheme>(
'app_theme',
values: AppTheme.values,
);
Usage:
final currentTheme = await appTheme.get(); // AppTheme.light / dark / systemawait appTheme.set(AppTheme.dark);
📚 Persisting a List of Enums
Define your enum:
enumPermission { read, write, delete }
Store a list using Prf.enumeratedList (cached) or PrfIso.enumeratedList (isolate-safe):
final permissions = Prf.enumeratedList<Permission>(
'user_permissions',
values: Permission.values,
);
Usage:
final current = await permissions.get(); // [Permission.read, Permission.write]await permissions.set([Permission.read, Permission.delete]);
🧠 Custom Types? No Problem
Want to persist something more complex?
Use Prf.json<T>() or PrfIso.json<T>() with any model that supports toJson and fromJson:
await favoriteBooks.set([book1, book2]);
final list = await favoriteBooks.get(); // List<Book>
🧩 Custom Casting Adapter with .cast()
Need to persist a custom object that can be converted to a supported type (like String, int and all 20+ types)?
Use the .cast() factory to define on-the-fly adapters with custom encode/decode logic — no full adapter class needed!
If you want instant, non-async access to a stored value, you can pre-load it into memory.
Use Prf.value<T>() to create a prf object that automatically initializes and caches the value.
Example:
final userScore = awaitPrf.value<int>('user_score');
// Later, anywhere — no async needed:print(userScore.cachedValue); // e.g., 42
Prf.value<T>() reads the stored value once and caches it.
You can access .cachedValue instantly after initialization.
If no value was stored yet, .cachedValue will be the defaultValue or null.
✅ Best for fast access inside UI widgets, settings screens, and forms.
⚠️ Not suitable for use across isolates — use .isolated or PrfIso<T> for isolate safety.
Quick Summary
await Prf.value<T>() → loads and caches the value.
.cachedValue → direct, instant access afterward.
No async needed for future reads!
💡 Altervative - .prf() from String Keys
final username = 'username'.prf<String>();
await username.set('Joey');
final name = await username.get();
Isolate-safe version:
final username = 'username'.prf<String>().isolated;
await username.set('Joey');
final name = await username.get();
Whether you're using the modern SharedPreferencesAsync or the legacy SharedPreferences, migrating to prf is simple and gives you cleaner, type-safe, and scalable persistence — without losing any existing data.
In fact, you can use prf with your current keys and values out of the box, preserving all previously stored data. But while backwards compatibility is supported, we recommend reviewing all built-in types and usage that prf provide — which may offer a cleaner, more powerful way to structure your logic going forward, without relying on legacy patterns or custom code.
✅ If you're already using SharedPreferencesAsync
You can switch to prf with zero configuration — just use the same keys.
Before (SharedPreferencesAsync):
final prefs = SharedPreferencesAsync();
await prefs.setBool('dark_mode', true);
final isDark = await prefs.getBool('dark_mode');
After (prf):
final darkMode = Prf<bool>('dark_mode');
await darkMode.set(true);
final isDark = await darkMode.get();
✅ As long as you're using the same keys and types, your data will still be there. No migration needed.
🧼 Or — if you don't care about previously stored values, you can start fresh and use prf types right away. They’re ready to go with clean APIs and built-in caching for all dart types, enums, JSONs, and more.
✅ If you're using the legacy SharedPreferences class
You can still switch to prf using the same keys:
Before (SharedPreferences):
final prefs = awaitSharedPreferences.getInstance();
await prefs.setString('username', 'Joey');
final name = prefs.getString('username');
After (prf):
final username = Prf<String>('username');
await username.set('Joey');
final name = await username.get();
⚠️ prf uses SharedPreferencesAsync, which is isolate-safe, more robust — and does not share data with the legacy SharedPreferences API. The legacy API is already planned for deprecation, so migrating away from it is strongly recommended.
✅ If you're still in development, you can safely switch to prf now — saved values from before will not be accessible, but that's usually fine while iterating.
The migration bellow automatically migrates old values into the new backend if needed.
Safe to call multiple times — it only runs once.
⚠️ If your app is already in production using SharedPreferences
If your app previously used SharedPreferences (the legacy API), and you're now using prf (which defaults to SharedPreferencesAsync):
You must run a one-time migration to move your data into the new backend (especially on Android, where the storage backend switches to DataStore).
Run this before any reads or writes, ideally at app startup:
awaitPrfService.migrateFromLegacyPrefsIfNeeded();
This ensures your old values are migrated into the new system.
It is safe to call multiple times — migration will only occur once.
Summary
Case
Do you need to migrate?
Do your keys stay the same?
Using SharedPreferencesAsync
❌ No migration needed
✅ Yes
Using SharedPreferences (dev only)
❌ No migration needed
✅ Yes
Using SharedPreferences (production)
✅ Yes — run migration once
✅ Yes
Starting fresh
❌ No migration, no legacy
🔄 You can pick new keys
With prf, you get:
🚀 Type-safe, reusable variables
🧠 Cleaner architecture
🔄 Built-in in-memory caching
🔐 Isolate-safe behavior with SharedPreferencesAsync
📦 Out-of-the-box support for 20+ types, enums, full JSON models and more
In addition to typed variables, prf connects seamlessly with additional persistence power tools — packages built specifically to extend the capabilities of prf into advanced real-world use cases.
These tools offer plug-and-play solutions that carry over the same caching, async-safety, and persistence guarantees you expect from prf.
Working with SharedPreferences directly can quickly become verbose, error-prone, and difficult to scale. Whether you’re building a simple prototype or a production-ready app, clean persistence matters.
❌ The Problem with Raw SharedPreferences
Even in basic use cases, you're forced to:
Reuse raw string keys (risk of typos and duplication)
Manually cast and fallback every read
Handle async boilerplate (getInstance) everywhere
Encode/decode complex types manually
Spread key logic across multiple files
Let’s see how this unfolds in practice.
Example: Saving and Reading Multiple Values
Goal: Save and retrieve a username, isFirstLaunch, and a signupDate.
SharedPreferences (verbose and repetitive)
final prefs = awaitSharedPreferences.getInstance();
// Save valuesawait prefs.setString('username', 'Joey');
await prefs.setBool('is_first_launch', false);
await prefs.setString(
'signup_date',
DateTime.now().toIso8601String(),
);
// Read valuesfinal username = prefs.getString('username') ?? '';
final isFirstLaunch = prefs.getBool('is_first_launch') ?? true;
final signupDateStr = prefs.getString('signup_date');
final signupDate = signupDateStr != null
? DateTime.tryParse(signupDateStr)
: null;
🔻 Issues:
Repeated string keys — no compile-time safety
Manual fallback handling and parsing
No caching — every .get hits disk
Boilerplate increases exponentially with more values
Example: Same Logic with prf
final username = Prf<String>('username');
final isFirstLaunch = Prf<bool>('is_first_launch', defaultValue: true);
final signupDate = Prf<DateTime>('signup_date');
// Saveawait username.set('Joey');
await isFirstLaunch.set(false);
await signupDate.set(DateTime.now());
// Readfinal name = await username.get(); // 'Joey'final first = await isFirstLaunch.get(); // falsefinal date = await signupDate.get(); // DateTime instance
💡 Defined once, used anywhere — fully typed, cached, and clean.
It Gets Worse with Models
Storing a User model in raw SharedPreferences requires:
Manual jsonEncode / jsonDecode
Validation on read
String-based key tracking
SharedPreferences with Model:
// Get SharedPreferencesfinal prefs = awaitSharedPreferences.getInstance();
// Encode to JSONfinal json = jsonEncode(user.toJson());
// Set valueawait prefs.setString('user_data', json);
// Readfinal raw = prefs.getString('user_data');
User? user;
if (raw != null) {
try {
// Decode JSONfinal decoded = jsonDecode(raw);
// Convert to User
user = User.fromJson(decoded);
} catch (_) {
// fallback or error
}
}
For most use cases, you can use built-in types or factories like Prf.enumerated<T>(), Prf.json<T>(), and now Prf.cast<T, TCast>() to persist almost anything.
This section is for advanced users who want full control — but with less boilerplate thanks to the new .cast() API.
I’m Jozz — and my packages share a simple philosophy: developer experience first.
I try to avoid boilerplate wherever possible, and most of these packages were born out of real needs in my own projects. Each one comes with clear documentation, minimal setup, and APIs that are easy to pick up without surprises.
They’re built to be lightweight, reliable, and ready for production, always with simplicity in mind. There are more packages in the works, following the same approach.
If you find them useful and feel like supporting, you’re welcome to do so (:
Because every byte counts. shrink makes data compression effortless with a one-line API and fully lossless results. It auto-detects the best method, often cutting size by 5× to 40× (and up to 1,000×+ for structured data). Perfect for Firestore, local storage, or bandwidth-sensitive apps. Backed by clear docs and real-world benchmarks.
Define once, track forever. track gives you plug-and-play tools for streaks, counters, activity logs, and records — all persisted safely across sessions and isolates. From daily streaks to rolling counters to best-ever records, it handles resets, history, and storage automatically. Clean APIs, zero boilerplate, and deeply detailed documentation.
hivez is a production-ready layer on top of Hive CE that keeps its raw speed but makes it safer and easier to use. It auto-initializes boxes, enforces type safety, and gives you a single unified API for Box, LazyBox, and IsolatedBox. Concurrency issues are handled with built-in locks, and you also get extras like backup/restore, search, and crash recovery. Backed by clear, detailed documentation, hivez is designed for real-world apps where you want Hive’s performance without the boilerplate or pitfalls.
Stop wrestling with DateTime and Duration. time_plus adds the missing tools you wish Dart had built in: add and subtract time units, start/end of day/week/month, compare by precision, yesterday/tomorrow, fractional durations, and more. Built with 128+ extensions, 700+ tests, and zero dependencies, it’s faster, more precise, and more reliable than the classic time package — while keeping APIs clear and intuitive. Ideal for scheduling, analytics, or any app where every microsecond counts.
Everything your widgets wish they had. exui is a zero-dependency extension library for Flutter with 200+ chainable utilities for padding, margin, centering, gaps, visibility, constraints, gestures, buttons, text styling, and more — all while keeping your widget tree fully native.
No wrappers. No boilerplate. Just concise, expressive methods that feel built into Flutter itself. Backed by hundreds of unit tests and exceptional documentation, exui makes UI code cleaner, faster, and easier to maintain.
One line. No boilerplate. No setup. limit gives you persistent cooldowns and token-bucket rate limiting across sessions, isolates, and restarts. Perfect for daily rewards, retry delays, API quotas, or chat limits. Define once, automate forever — the system handles the timing, persistence, and safety behind the scenes. Clear docs and practical examples included.
📢 jozz_events – Strongly-Typed Events for Clean Architecture
A domain-first, framework-agnostic event bus built for scalable apps. jozz_events enables decoupled, strongly-typed communication between features and layers — without the spaghetti. It’s lightweight, dependency-free, lifecycle-aware, and integrates naturally with Clean Architecture. Ideal for Flutter or pure Dart projects where modularity, testability, and clarity matter most.