Flutter - Making Purchases

Learn how to make and restore mobile purchases using Adapty Flutter SDK. Adapty handles server-side validation, including renewals and grace periods

To make the purchase, you have to call .makePurchase() method:

try {
    final MakePurchaseResult makePurchaseResult = await Adapty.makePurchase(product);
} on AdaptyError catch (adaptyError) {}
catch (e) {}

Request parameters:

  • Product (required): an AdaptyProduct object retrieved from the paywall.

Response parameters:

  • Purchaser info: an AdaptyPurchaserInfo object. This model contains info about access levels, subscriptions, and non-subscription purchases. Generally, you have to check only access level status to determine whether the user has premium access to the app.

🚧

Make sure you've added App Store Shared Secret for iOS and uploaded Service Account Key File for Android in Adapty Dashboard, without them, we can't validate purchases.

Below is a complete example of making the purchase and checking the user's access level.

try {
  final MakePurchaseResult makePurchaseResult = await Adapty.makePurchase(product);
  // "premium" is an identifier of default access level
  if (makePurchaseResult.purchaserInfo?.accessLevels['premium']?.isActive ?? false) {
    // grant access to premium features
  }
} on AdaptyError catch (adaptyError) {}
catch (e) {}

🚧

Make sure to set up App Store Server Notifications for iOS and Real-time Developer Notifications (RTDN) for Android to receive subscription updates without significant delays.

Restoring purchases

To restore purchases, you have to call .restorePurchases() method:

try {
    final RestorePurchasesResult restorePurchasesResult = await Adapty.restorePurchases();
    
    // "premium" is an identifier of default access level
    if (restorePurchasesResult?.purchaserInfo?.accessLevels['premium']?.isActive ?? false) {
        // grant access to premium features
    }
} on AdaptyError catch (adaptyError) {}
catch (e) {}

Response parameters:

  • Purchaser info: an AdaptyPurchaserInfo object. This model contains info about access levels, subscriptions, and non-subscription purchases. Generally, you have to check only access level status to determine whether the user has premium access to the app.

Redeeming an Offer Code

Since iOS 14.0 your iOS users can redeem Offer Codes. To allow them to do so, you can present the Offer Code redemption sheet by calling the related SDK method.

Purchases performed within this page would be tracked via an info update listener.

try {
    await Adapty.presentCodeRedemptionSheet();
on AdaptyError catch (adaptyError) {}
catch (e) {}

Did this page help you?