fetchProducts static method

Future<LinkFiveProducts?> fetchProducts()

By Default, the plugin does not fetch any Products to offer.

You have to call this method at least once. The best case would be to call fetchProducts whenever you want to show your offer to the user e.g. on the paywall page

This method will call LinkFive to get all available products for the user and then uses the native platform to fetch the product information

This method will return the Products but will also send the products to the LinkFivePurchases.products stream

riverpod example:

class PremiumOfferNotifier extends Notifier<LinkFiveProducts?> { /// fetched once whenever the user enters the paywall Future

void purchase(LinkFiveProductDetails productDetails) { LinkFivePurchases.purchase(productDetails.productDetails); }

void restore() { LinkFivePurchases.restore(); }

@override LinkFiveProducts? build() { return null; } }

widget example:

class _PurchasePaywall extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final premiumOffer = ref.watch(premiumOfferProvider); if (premiumOffer == null) { // return Page Loading Widget }

return ListView(children: [
    for (final offer in premiumOffer.productDetailList)
      switch (offer.productType) {
          LinkFiveProductType.OneTimePurchase => LayoutBuilder(builder: (_, _) {
            // build your One Time Purchase Widget
            // e.g:
            // Text(offer.oneTimePurchasePrice.formattedPrice)

            // and later when pressed:
            // onPressed: () {
            //   ref.read(premiumOfferProvider.notifier).purchase(offer);
            // }
          }),
          LinkFiveProductType.Subscription => LayoutBuilder(builder: (_, _) {
            // build your Subscription Purchase Widget
            // use the pricing Phases:
            // for (var pricingPhase in offer.pricingPhases) {
            //   Text(pricingPhase.formattedPrice);
            //   Text(pricingPhase.billingPeriod.iso8601); // e.g.: P6M
            // }

            // and later when pressed:
            // onPressed: () {
            //   ref.read(premiumOfferProvider.notifier).purchase(offer);
            // }
          }),
      }
    ]
);

} }

@return LinkFiveProducts or null if no subscriptions found

Implementation

static Future<LinkFiveProducts?> fetchProducts() {
  return LinkFivePurchasesImpl().fetchProducts();
}