LinkFive - Successful Subscriptions

Get All Active Subscriptions

Get All Active Subscriptions

Please read How to initialize the plugin before you start with this part.

Usually you would want to know, if the user already purchased a subscription after app start. In this case the flutter plugin has a function to get all active subscriptions.

If the user has no active subscriptions, you might want to offer a subscription to the user by fetching all available subscriptions.

Receive all Active Subscriptions / Plans

LinkFive mainly works with streams. You can listen to a stream using the LinkFivePurchases static object. To get all active subscriptions, you need to get the stream by calling .activeProducts and listen on the Stream.

// somewhere in your code
LinkFivePurchases
.activeProducts
.listen(_activeProductsUpdate))
//...
void _activeProductsUpdate(LinkFiveActiveProducts data) {
// save the data, or parse it.
activeProducts = data;
// in a provider, you might want to notify all listeners
notifyListeners();
}

The stream will pass all verified and active subscriptions to your app. We also check if the receipt is valid by calling the Apple or Google APIs.

Cancel your stream when done

In your dispose method, please don't forget to cancel the stream by calling cancel.

Looking at the first example above, you would want to save the result of the stream and call cancel on dispose.

_stream = LinkFivePurchases
.activeProducts
.listen(_activeProductsUpdate);
//...
void dispose() async {
await _stream.cancel();
super.dispose();
}

Active Subscriptions using the Provider Plugin

No additional work needed. You will find all active subscriptions in your provider.

// Access all active subscriptions after consuming LinkFiveProvider
linkFiveProvider.activeProducts

Next: Show your Subscription Offer