callDealerAssetApi method

Future<void> callDealerAssetApi(
  1. String filterStatus,
  2. String userId,
  3. String productCode,
  4. StockDealerContentModel? modelData,
  5. CheckStockContentModel? modelProduct,
  6. String? keyword,
  7. String? startRange,
  8. String? endRange,
  9. String? fromPurchase,
  10. String? toPurchase,
  11. String? fromExpiry,
  12. String? toExpiry,
  13. int pageNo, {
  14. int pageCount = 20,
  15. required bool isFromCheckin,
  16. required int categoryId,
  17. required String categoryName,
})

Implementation

Future<void> callDealerAssetApi(
  String filterStatus,
  String userId,
  String productCode,
  StockDealerContentModel? modelData,
  CheckStockContentModel? modelProduct,
  String? keyword,
  String? startRange,
  String? endRange,
  String? fromPurchase,
  String? toPurchase,
  String? fromExpiry,
  String? toExpiry,
  int pageNo, {
  int pageCount = 20,
  required bool isFromCheckin,
  required int categoryId,
  required String categoryName,
  //String? query,
}) async {
  try {
    Helper.hideKeyboard();
    BuildContext context = Get.context!;
    if (pageNo == 1) {
      Helper.progressDialog(context, "Please wait..");
    }
    String requestTime = "";
    String responseTime = "";
    await ApiClient(
      baseUrl: ApiConstant.armBaseUrl,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "checkStock",
    )
        .getAssetDetails(
      filterRetailerNumber: userId,
      filterStatusId: "4",
      pageNo: pageNo,
      assetStartRange: startRange,
      assetEndRange: endRange,
      filterPurchaseFromDate: fromPurchase,
      filterPurchaseToDate: toPurchase,
      filterExpiryFromDate: fromExpiry,
      filterExpiryToDate: toExpiry,
      perPageCount: pageCount,
      filterProductCode: productCode,
      xUserId: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
      sort: "serialnumberNumeric",
      filterSerialNumberLike: keyword,
    )
        .then((response) {
      Helper.logEvent(
        "RESPONSE_EVENT",
        success: true,
        endPoint: Api.getAssetDetails,
        responseDate: responseTime,
        screenName: "checkStock",
        requestDate: requestTime,
      );
      StockDealerAssetModel model = response;
      if (model.status == true) {
        if (model.data != null) {
          if (pageNo == 1) {
            dealerAssetList.value = model.data!.content ?? [];
            dealerSearchedAssetList.value = dealerAssetList;
          } else {
            dealerAssetList.addAll(model.data!.content ?? []);
            dealerSearchedAssetList.value = dealerAssetList;
          }
        }
        totalList = model.data!.totalElements ?? 0;
        isLoadingMore.value = false;
        /* Get.to(
          () => CheckStockAsset(
            dealerModel: modelData,
            model: modelProduct,
            isFromCheckin: isFromCheckin,
          ),
        );*/
        // if (pageNo == 1) {
        //   Get.back();
        //   if (query == null) {
        //     CheckStockAssetBottomSheet().checkStockAsset(
        //       context,
        //       modelProduct,
        //       isFromCheckin,
        //       pageNo,
        //     );
        //   }
        // }
        if (pageNo == 1) {
          Get.back();
          //if (keyword == null) {
          Get.to(
            () => CheckStockAssetDetails(
                modelProduct: modelProduct,
                categoryId: categoryId,
                categoryName: categoryName),
          );
          //}
        }
      } else {
        if (model.errors != null) {
          Helper.messageDialog(
            Get.context!,
            model.errors![0].errorCode ?? localization.translate("tryAgain"),
            model.errors![0].errorDescription ??
                localization.translate("somethingWentWrong"),
          );
        }
      }
    }).catchError((error) {
      ConditionalLogs().customLog("$error");
      if (pageNo == 1) {
        Get.back();
      }
      MainController mainController = Get.put(MainController());
      mainController.showErrorPopup();
    });
  } catch (e) {
    if (pageNo == 1) {
      Get.back();
    }
  }
}