PurchaseLedgerService class

Thin local cache on top of PurchaseSeam for the 2 purchase shapes almost every game needs and would otherwise re-implement per project: a consumable with a remaining balance ("5 hint tokens left") and a permanent one-time unlock ("remove ads", "premium skin pack").

This is NOT a receipt-validation layer. It trusts whatever it's told — grantConsumable/grantPermanent are meant to be called by the app's own PurchaseSeam adapter, and ONLY after that adapter has already verified the purchase through the real store/server. This service persists the resulting balance/ownership locally; it has no way to detect a fabricated grant call, same trust-boundary framing as save_integrity.dart's "best-effort local cache, not a substitute for server-side validation" doc.

Inheritance
  • Object
  • GetLifeCycle
  • DisposableInterface
  • GetxService
  • PurchaseLedgerService

Constructors

PurchaseLedgerService({String? storageKey})

Properties

debugPendingSaves → Future<void>
Awaits every save queued so far — lets a test deterministically wait for a burst of rapid calls to fully settle instead of guessing a delay.
no setter
hashCode → int
The hash code for this object.
no setterinherited
initialized → bool
Checks whether the controller has already been initialized.
no setterinherited
isClosed → bool
Checks whether the controller has already been closed.
no setterinherited
onDelete → InternalFinalCallback<void>
Internal callback that starts the cycle of this controller.
finalinherited
onStart → InternalFinalCallback<void>
Called at the exact moment the widget is allocated in memory. It uses an internal "callable" type, to avoid any @overrides in subclases. This method should be internal and is required to define the lifetime cycle of the subclass.
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

$configureLifeCycle() → void
inherited
balanceOf(String sku) → int
sku's current consumable balance, 0 if never granted (never throws).
consume(String sku, int amount) → bool
Spends amount from sku's consumable balance. Returns true if the balance covered it (and was deducted); false (never throws, balance left untouched) if sku has fewer than amount remaining — this is the guard against the balance ever going negative.
grantConsumable(String sku, int amount) → void
Adds amount to sku's consumable balance.
grantPermanent(String sku) → void
Marks sku as permanently owned. Safe to call again for an already-owned sku — stays owned, no error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onClose() → void
Called before onDelete method. onClose might be used to dispose resources used by the controller. Like closing events, or streams before the controller is destroyed. Or dispose objects that can potentially create some memory leaks, like TextEditingControllers, AnimationControllers. Might be useful as well to persist some data on disk.
inherited
onInit() → void
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
inherited
onReady() → void
Called 1 frame after onInit(). It is the perfect place to enter navigation events, like snackbar, dialogs, or a new route, or async request.
inherited
owns(String sku) → bool
true once sku has been grantPermanented, false (never throws) otherwise.
revokeConsumable(String sku, int amount) → void
Reverses a grantConsumable — subtracts amount from sku's balance for a store refund/chargeback arriving after the original grant. Clamped at 0 (never throws RangeError) rather than going negative: the player may have already spent some of that balance by the time the refund lands, and a negative "debt" balance has no meaningful interpretation here.
revokePermanent(String sku) → void
Reverses a grantPermanent — for a store refund/chargeback. Safe to call for a sku never granted (no-op, mirrors grantPermanent's own "safe to call again" symmetry).
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

maybe → PurchaseLedgerService?
Gets the instance if already registered (safe to call from game/widget tests).
no setter