present static method

Future<void> present(
  1. BuildContext context
)

Presents an Offer to the user and allows them to accept or decline it, which can result in a new LicenseRecord being created based on the presented Offer.

If the Offer has already been accepted by the user, this method does nothing.

This method creates a new UIHostingController that holds the Tiki SDK's pre-built user interface for the Offer prompt and presents it with the current root view controller. When the user finishes the Offer flow by dismissing it or accepting/declining the Offer, the root view controller is called again to dismiss the created hosting controller.

It throws a StateError if the SDK is not initialized or if no Offer was created.

Implementation

static Future<void> present(BuildContext context) async {
  _throwIfNotInitialized();
  _throwIfNoOffers();
  String ptr = TikiSdk.instance.offers.values.first.getPtr;
  List<LicenseUsecase> usecases = [];
  List<String> destinations= [];
  TikiSdk.instance.offers.values.first.getUses.forEach( (licenseUse) {
    if(licenseUse.destinations != null){
      destinations.addAll(licenseUse.destinations!);
    }
    usecases.addAll(licenseUse.usecases);
  });
  await guard(ptr, usecases, destinations: destinations, onFail: (_) => showModalBottomSheet<dynamic>(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (BuildContext context) => OfferPrompt()));
}