getPurchaseList method

Future<String> getPurchaseList({
  1. bool forceFetchPurchaseHistory = false,
  2. bool fetchPurchaseFromLocal = false,
})

Implementation

Future<String> getPurchaseList(
    {bool forceFetchPurchaseHistory = false,
    bool fetchPurchaseFromLocal = false}) async {
  SharedPreferences sharedPreferences = await DeviceStorage().getInstance();
  String purchaseListData =
      sharedPreferences.getString(DeviceStorage.purchaseListData) ?? "";

  if (fetchPurchaseFromLocal) {
    return purchaseListData;
  }
  if (purchaseListData.isEmpty || forceFetchPurchaseHistory) {
    try {
      purchaseListData = await NetworkHandler.getPurchaseList();
      await sharedPreferences.setString(
          DeviceStorage.purchaseListData, purchaseListData);
    } catch (error) {
      purchaseListData = "";
    }
  }
  return purchaseListData;
}