Subscription Status

Learn how to get info about user subscription status and grant access to the premium features of the app using Adapty Flutter SDK

With Adapty you don't have to hardcode product ids to check subscription status. You just have to verify that the user has an active access level. To do this, you have to call .getPurchaserInfo() method:

try {
    GetPurchaserInfoResult getPurchaserInfoResult = await Adapty.getPurchaserInfo(bool forceUpdate = false);
} on AdaptyError catch (adaptyError) {}
catch (e) {}

Request parameters:

  • Force update (optional): a boolean indicating whether Adapty should fetch the data from API or get it from the local cache. Adapty SDK regularly refreshes the local data, so most of the time you don't have to use this flag. By default, it's set to false.

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.

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

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

📘

You can have multiple access levels per app. For example, if you have a newspaper app and sell subscriptions to different topics independently, you can create access levels "sports" and "science". But most of the time, you will only need one access level, in that case, you can just use the default "premium" access level.

Read more about access levels in the Access Level section.

Listening for subscription status updates

Adapty.purchaserInfoUpdateStream.listen((purchaserInfo) {
    if (purchaserInfo.accessLevels['premium']?.isActive ?? false) {
    // grant access to premium features
  }
});

🚧

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.


Did this page help you?