init method

Future<LinkFiveActiveProducts> init(
  1. String apiKey, {
  2. LinkFiveLogLevel logLevel = LinkFiveLogLevel.WARN,
  3. LinkFiveEnvironment env = LinkFiveEnvironment.PRODUCTION,
})

Initialize the LinkFive client with .init(...)

This will check all active Subscriptions

apiKey get your API Key in the API section of LinkFive logLevel default is DEBUG. Possible values are TRACE, DEBUG, INFO, WARN, ERROR env default is Production. Sets the LinkFive Environment.

Implementation

Future<LinkFiveActiveProducts> init(String apiKey,
    {LinkFiveLogLevel logLevel = LinkFiveLogLevel.WARN,
    LinkFiveEnvironment env = LinkFiveEnvironment.PRODUCTION}) async {
  if (appDataStore.apiKey.isNotEmpty) {
    LinkFiveLogger.w("LinkFive is already Initialized. Please only call init once");
    return _store.latestLinkFiveActiveProducts ?? LinkFiveActiveProducts.empty();
  }

  LinkFiveLogger.setLogLevel(logLevel);

  // init Preferences
  // does nothing else than putting the shared preference instance in place
  await LinkFivePrefs().init();

  // LinkFive User Management
  // also loads the saved LinkFive User ID if available
  await LinkFiveUserManagement().init();

  // Init the App Data Store
  // this also includes to load data from shared Preferences
  await appDataStore.init(apiKey);

  if (appDataStore.isTestKey) {
    // The Test key is used to test the basic LinkFive features.
    LinkFiveLogger.w("--------------------LinkFive-test--------------------");
    LinkFiveLogger.w(
        "TEST KEY DETECTED. Please use this only for TESTING and switch to a real API key. Go to https://www.linkfive.io and register");
    LinkFiveLogger.w("Thank you!");
    _client = LinkFiveClientTest();
    _billingClient = LinkFiveBillingClientTest();
    LinkFiveLogger.w("Test Client initialized");
    LinkFiveLogger.w("--------------------LinkFive-test--------------------");
  }

  // init the client http client. sets the url etc.
  _client.init(env, appDataStore);

  LinkFiveLogger.d("init LinkFive");

  // main method for purchases.
  // if a purchase was made, we get an update
  _listenPurchaseUpdates();

  // if not initialized yet, load all active subs and send to LinkFive
  // if (!(await LinkFivePrefs().hasInitialized)) {
  // await _loadActiveSubs();
  // } else {
  // Check LinkFive For Active Plans
  final activePlans = await _updateActivePlansFromLinkFive();
  finishInitialize();

  return activePlans;
  // }
}