TipLedger class
Persistent "have we shown tip X?" store, backed by one SharedPreferences
key. Process-wide singleton — widgets like DiscoveryBadgeWrapper reach
for it directly via TipLedger().
Call init once at app start (before running any emits). Pass a custom storageKey if you want to isolate state per-flavor or avoid collision with a previous install of the same package.
JSON shape written to the chosen key:
{
"version": 1,
"seen": { "<tipId>": <epochMillis>, ... },
"asked": { "<tipId>": <epochMillis>, ... },
"counters": { "<counter_key>": <int>, ... }
}
Constructors
- TipLedger()
-
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInitialized → bool
-
True once init has loaded (or started fresh).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storageKey → String
-
Storage key currently in use.
no setter
Methods
-
clearSeen(
String tipId) → Future< void> -
Clear the seen flag for
tipId(re-enables the tip on its next emit). -
counter(
String key) → int - Current value of a named counter, or 0 if never set.
-
dump(
) → Map< String, dynamic> - Shallow copy of internal state. Useful for debugging / exporting.
-
hasBeenAsked(
String tipId) → bool -
Whether
tipIdhas been marked asked via markAsked (e.g. a permission prompt was shown, regardless of user's answer). -
hasSeen(
String tipId) → bool -
Whether
tipIdhas been marked seen via markSeen. -
incCounter(
String key) → Future< int> - Increment a named counter by one and return the new value.
-
init(
{String storageKey = defaultStorageKey}) → Future< void> -
Load the ledger from
SharedPreferences. Safe to call multiple times — subsequent calls are no-ops unless the key changes, in which case the ledger re-loads against the new key. -
markAsked(
String tipId) → Future< void> -
Mark
tipIdas asked and persist. No-op if already marked. -
markSeen(
String tipId) → Future< void> -
Mark
tipIdas seen and persist. No-op if already marked. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resetForTests(
) → Future< void> - Reset all in-memory and persisted state. Test-only helper — calling this in production will wipe the user's real ledger.
-
seenNotifier(
String tipId) → ValueNotifier< bool> -
ValueNotifierthat flips totrueonce markSeen fires fortipId. Listenable UIs (e.g. a "New" badge) can subscribe to auto-clear without explicit wiring. -
setCounter(
String key, int value) → Future< void> - Overwrite the value of a named counter.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultStorageKey → const String