prf library

PRF - Define. Get. Set. Done.

A powerful, type-safe, and developer-friendly persistence library that simplifies working with SharedPreferences in Flutter applications.

PRF offers a clean, concise API for storing and retrieving values with zero boilerplate, no string repetition, and strong type safety. It supports both cached access (Prf) for performance and isolate-safe access (PrfIso) for reliability across multiple isolates.

Key Features:

  • Type Safety — Define variables once, use them anywhere with full type checking
  • Caching — Automatic in-memory caching with Prf for fast access
  • Isolate SafetyPrfIso ensures true isolate-safe access (always reads from disk)
  • Extended Type Support — Beyond primitives: DateTime, BigInt, Duration, enums, JSON models, and binary data
  • Zero Setup — No manual initialization — define and use immediately
  • Production UtilitiesPrfCooldown for managing cooldowns, PrfRateLimiter for rate limiting
  • Custom Adapters — Extend behavior easily with custom serialization, compression, encryption

Basic Usage:

// Define persistent variables
final username = Prf<String>('username');
final darkMode = Prf<bool>('dark_mode', defaultValue: false);

// Set values
await username.set('Alice');
await darkMode.set(true);

// Get values
final name = await username.get();
final isDark = await darkMode.get();

Specialized Types

Use simple factory methods instead of dedicated classes:

  • Prf.enumerated<T>() / PrfIso.enumerated<T>() — for enum values
  • Prf.json<T>() / PrfIso.json<T>() — for custom JSON model objects

Custom Adapters

PRF supports a fully modular adapter system. Built-in adapters cover common types, but you can easily create and register your own for any custom type, compressed format, or encrypted payload.

See PrfAdapter and PrfAdapterMap for details.

Classes

BaseCounterTracker
An abstract class for tracking integer counters with expiration logic.
BasePrfObject<T>
Base class for preference objects that provides core functionality for storing and retrieving typed values from SharedPreferences.
BaseServiceObject
An abstract base class for service objects that provides caching options.
BaseTracker<T>
An abstract base class for tracking values with expiration logic.
BigIntAdapter
Adapter for BigInt objects.
BigIntListAdapter
Adapter for lists of BigInt values.
BinaryListAdapter<T>
An abstract adapter for encoding and decoding lists of binary data.
BoolAdapter
Adapter for boolean values.
BoolListAdapter
Adapter for lists of booleans.
BytesAdapter
Adapter for binary data (Uint8List).
BytesListAdapter
Adapter for lists of binary data (Uint8List).
CachedPrfObject<T>
A preference object that caches values in memory for faster access.
DateTimeAdapter
Adapter for DateTime objects.
DateTimeListAdapter
Adapter for lists of DateTime objects.
DoubleAdapter
Adapter for double values.
DoubleListAdapter
Adapter for lists of doubles.
DurationAdapter
Adapter for Duration objects.
DurationListAdapter64
Adapter for lists of Duration objects.
EnumAdapter<T extends Enum>
Adapter for Enum values.
IntAdapter
Adapter for integer values.
IntListAdapter
Adapter for lists of integers.
JsonAdapter<T>
Adapter for objects that can be converted to and from JSON.
NumAdapter
Adapter for numeric values.
NumListAdapter
A NumListAdapter is a specialized BinaryListAdapter for handling lists of numeric values, encoding them as Base64 strings for storage.
Prf<T>
A cached preference object that provides type-safe access to SharedPreferences.
PrfActivityCounter
A utility class for tracking user activity over time across various spans such as hour, day, month, and year. It provides persistent storage and retrieval of activity data, making it suitable for usage statistics, trend analysis, and generating long-term activity reports.
PrfAdapter<T>
Abstract adapter for converting between Dart types and SharedPreferences.
PrfAdapterMap
Registry for managing adapters that convert between Dart types and SharedPreferences.
PrfBigInt
A cached BigInt preference.
PrfBool
A cached boolean preference.
PrfBytes
A cached preference for Uint8List.
PrfCooldown
A utility for managing cooldown logic using persisted DateTime and Activation Count.
PrfDateTime
A cached DateTime preference.
PrfDouble
A cached double preference.
PrfDuration
A cached Duration preference.
PrfEncodedAdapter<T, TStore>
Base adapter for types that need encoding before storing in SharedPreferences.
PrfEnum<T extends Enum>
A cached preference object for enum values.
PrfInt
A cached integer preference.
PrfIso<T>
An isolate-safe preference object that provides type-safe access to SharedPreferences.
PrfJson<T>
A cached preference object for JSON-serializable objects.
PrfPeriodicCounter
A persistent counter that automatically resets at the start of each aligned time period.
PrfRateLimiter
A robust, industry-grade token bucket rate limiter using prf.
PrfRateLimiterStats
PrfRolloverCounter
PrfRolloverCounter is a persistent counter designed to automatically reset after a specified duration from the last update. This is particularly useful for tracking rolling activity windows, such as "submissions per hour" or "attempts every 10 minutes".
PrfService
Service for accessing and managing SharedPreferences.
PrfStreakTracker
A persistent streak tracker for managing activity streaks with automatic expiration logic.
PrfString
A cached preference object for String values.
PrfStringList
A cached string list preference.
PrfThemeMode
A cached preference for ThemeMode.
Prfy<T>
An isolate-safe preference object.
PrfyEnum<T extends Enum>
An isolate-safe enum preference.
PrfyJson<T>
An isolate-safe JSON preference.
StringAdapter
Adapter for string values.
StringListAdapter
Adapter for lists of strings.
UriAdapter
Adapter for URI values.
UriListAdapter
Adapter for lists of Uri objects.

Enums

ActivitySpan
Enum representing the different spans of activity tracking.
TrackerPeriod
Represents different time periods for tracking purposes.

Extensions

PrfOperationExtensions on BasePrfObject<T>
Extension methods for BasePrfObject to provide convenient access.
TrackerPeriodExt on TrackerPeriod
Extension on TrackerPeriod to provide additional functionality.