IapResult class

Result of a purchase operation.

Use functional patterns to handle success and failure:

// Using fold
result.fold(
  onSuccess: (receipt) => unlockFeature(),
  onFailure: (failure) => showError(failure.message),
);

// Using when (with cancelled handling)
result.when(
  success: (receipt) => unlockFeature(),
  cancelled: () => showSnackBar('Purchase cancelled'),
  failure: (failure) => showError(failure.message),
);

// Chaining
result
  .onSuccess((receipt) => saveReceipt(receipt))
  .onFailure((failure) => logError(failure));

Constructors

IapResult.cancelled([String? message])
Creates a cancelled result.
factory
IapResult.failure(IapFailure failure)
Creates a failed result.
factory
IapResult.success(IapReceipt receipt)
Creates a successful result with receipt.
factory

Properties

cancelled bool
Whether the user cancelled the purchase.
no setter
errorCode String
Error code (empty if successful).
no setter
errorMessage String
Error message (empty if successful).
no setter
failed bool
Whether the purchase failed.
no setter
failure IapFailure?
The failure information (null if successful).
no setter
hashCode int
The hash code for this object.
no setterinherited
receipt IapReceipt?
The purchase receipt (null if failed).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
success bool
Whether the purchase was successful.
no setter

Methods

fold<T>({required T onSuccess(IapReceipt receipt), required T onFailure(IapFailure failure)}) → T
Handle success and failure cases.
getReceiptOrNull() IapReceipt?
Get receipt or null.
getReceiptOrThrow() IapReceipt
Get receipt or throw.
mapReceiptOr<T>(T mapper(IapReceipt receipt), T defaultValue) → T
Map receipt to another value, or return default.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCancelled(void callback()) IapResult
Execute callback on cancellation (chainable).
onFailure(void callback(IapFailure failure)) IapResult
Execute callback on failure (chainable).
onSuccess(void callback(IapReceipt receipt)) IapResult
Execute callback on success (chainable).
toString() String
A string representation of this object.
override
when<T>({required T success(IapReceipt receipt), required T cancelled(), required T failure(IapFailure failure)}) → T
Handle success, cancelled, and failure cases separately.

Operators

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