getState method

Future<String> getState(
  1. Datum content, {
  2. bool clearleadCheck = true,
  3. bool ignoreClearLead = false,
})

Implementation

Future<String> getState(Datum content,
    {bool clearleadCheck = true, bool ignoreClearLead = false}) async {
  String buttonStatus = "";
  bool isLoggedin = await LoginService().isLoggedIn();
  if (!isLoggedin) {
    buttonStatus = login;
    buttonStatus = getClearLeadMode(content, buttonStatus, clearleadCheck);
    return buttonStatus;
  }

  AvailabilityService availabilityService = AvailabilityService();
  String mode = "";
  try {
    mode = await availabilityService.checkAvailability(content);
  } catch (err) {
    return notAvailable;
  }
  if (mode == AvailabilityService.free) {
    buttonStatus = play;
  } else if (mode == AvailabilityService.plan) {
    bool isSubscribed = await availabilityService.checkSubscription();
    if (isSubscribed) {
      buttonStatus = play;
    } else {
      buttonStatus = subscribe;
      if (!ignoreClearLead) {
        buttonStatus =
            getClearLeadMode(content, buttonStatus, clearleadCheck);
      }
    }
  } else if (mode == AvailabilityService.paid) {
    bool hasPaid = await availabilityService.checkPurchase(content);
    if (hasPaid) {
      buttonStatus = play;
    } else {
      buttonStatus = buy;
      if (!ignoreClearLead) {
        buttonStatus =
            getClearLeadMode(content, buttonStatus, clearleadCheck);
      }
    }
  } else if (mode == AvailabilityService.rental) {
    buttonStatus = rental;
    buttonStatus = getClearLeadMode(content, buttonStatus, clearleadCheck);
  }

  return buttonStatus;
}