No boilerplate. No setup. No repeated strings. Define your variables once, then get()
and set()
them anywhere with zero friction. prf
makes local persistence faster, simpler, and easier to scale. Includes 10+ built-in types and utilities like persistent cooldowns and rate limiters. Designed to fully replace raw use of SharedPreferences
.
Way more types than SharedPreferences — including
enums
DateTime
JSON models
and more.
NEW
PrfCooldown
&PrfRateLimiter
for persistent cooldowns and rate limiters.
Define → Get → Set → Done
Just define your variable once — no strings, no boilerplate:
final username = PrfString('username');
Then get it:
final value = await username.get();
Or set it:
await username.set('Joey');
That’s it. You’re done. Works with all prf
Types!
Available Methods for All prf
Types
Every prf
variable supports these methods:
get()
— Returns the current value (cached or from disk)set(value)
— Saves the value and updates the cacheremove()
— Deletes the value from storage and memoryisNull()
— Returnstrue
if the value isnull
getOrFallback(fallback)
— Returns the value or a fallback ifnull
existsOnPrefs()
— Checks if the key exists in SharedPreferences
Supported prf
Types
Define your variable once using the type you need:
PrfBool
— for feature flags and togglesPrfInt
— for counters, scores, timestampsPrfDouble
— for sliders, ratings, precise valuesPrfString
— for usernames, tokens, IDsPrfStringList
— for tags, recent items, multiselectsPrfEnum<T>
— for typed modes, states, user rolesPrfJson<T>
— for full models usingtoJson
/fromJson
PrfBytes
— for binary data like images or QR codesPrfDateTime
— for timestamps, cooldowns, scheduled events
NEW
PrfDuration
— for intervals, expiry timers
NEW
PrfBigInt
— for large numbers, cryptographic tokens
NEW
PrfThemeMode
— for theme (light/dark/system) settings
Persistent Services & Utilities:
NEW -
PrfCooldown
— for managing cooldown periods (e.g. daily rewards, retry delays)
NEW -
PrfRateLimiter
— token-bucket limiter for rate control (e.g. 1000 actions per 15 minutes)
Code Comparison
Using SharedPreferences
:
final prefs = await SharedPreferences.getInstance();
await prefs.setString('username', 'Joey');
final username = prefs.getString('username') ?? '';
Using prf
:
final username = PrfString('username');
await username.set('Joey');
final name = await username.get();
If you’re tired of:
- Duplicated string keys
- Manual casting and null handling
- Scattered boilerplate
Then prf
is your drop-in solution for fast, safe, scalable, and elegant local persistence.
What Sets prf
Apart?
Single definition — just one line to define, then reuse anywhere
Type-safe — no casting, no runtime surprises
Automatic caching — values are stored in memory after the first read
Lazy initialization — no need to manually call
SharedPreferences.getInstance()
Supports more than just primitives — 10+ types without counting utilities.
Built for testing — easily reset or mock storage in tests
Cleaner codebase — no more scattered
prefs.get...()
or typo-prone string keys
NEW in v2:
Isolate-safe — built on
SharedPreferencesAsync
for full isolate compatibility, with caching on top, making it faster and more ergonomic than working with raw SharedPreferencesAsync
directly
Persistent utilities included -
PrfCooldown
& PrfRateLimiter
This started as a private tool I built for my own apps — I used it daily on multiple projects and now after refining it for a long time, I finally decided to publish it. It’s now production-ready, and comes with detailed documentation on every feature, type, and utility.
If you find prf
useful, I’d really appreciate it if you give it a like on pub.dev and share it with your developer friends, it’s time we say goodbye to scattered prefs.get…() calls and start writing cleaner, smarter preference logic.
Feel free to open issues or ideas on GitHub!