callHistoryAssetsApi method

Future<void> callHistoryAssetsApi(
  1. CollectStockHistoryDetailsContentModel data,
  2. String transactionId, {
  3. String? search,
  4. required String productCode,
  5. required int offset,
})

Implementation

Future<void> callHistoryAssetsApi(
  CollectStockHistoryDetailsContentModel data,
  String transactionId, {
  String? search,
  required String productCode,
  required int offset,
}) async {
  BuildContext context = Get.context!;
  if (offset == 0) {
    Helper.progressDialog(context, "Please wait..");
  }

  try {
    String requestTime = "";
    String responseTime = "";
    asset.CollectHistoryAssetsModel model = await ApiClient(
      baseUrl: ApiConstant.posBFF,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "collectStockHistory",
    ).getCollectHistoryAssets(
      productCode: productCode,
      assetsTransactionId: transactionId,
      search: search,
      offset: offset,
      type: "SCAN_IN",
    );
    isLoadingMore.value = false;
    Helper.logEvent(
      "RESPONSE_EVENT",
      success: true,
      endPoint: "${Api.getCollectHistoryAssets}/SCAN_IN/assets",
      responseDate: responseTime,
      screenName: "collectStockHistory",
      requestDate: requestTime,
    );
    if (model.status == "POS200" && model.data != null) {
      totalAssets = model.data!.totalElements ?? 0;
      if (offset == 0) {
        searchedHistoryAssetList.value = model.data!.list ?? [];
        Get.back();
        if (search == null) {
          showModalBottomSheet(
            enableDrag: false,
            context: context,
            isScrollControlled: true,
            isDismissible: true,
            backgroundColor: Colors.transparent,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(
                SizeConstant.getHeightWithScreen(20),
              ),
            ),
            builder: (BuildContext context) {
              return ScannedAssetsBottomsheet(
                model: data,
                productCode: productCode,
                assetsTransactionId: transactionId,
              );
            },
          );
        }
      } else {
        searchedHistoryAssetList.addAll(model.data!.list ?? []);
      }
    } else {
      if (offset == 0) {
        Get.back();
      }
      if (model.errors != null) {
        Helper.messageDialog(
            Get.context!,
            model.errors![0].errorCode ?? "tryAgain".tr,
            model.errors![0].errorDescription ?? "technicalErrorMsg".tr);
      }
    }
  } catch (err, stacktrace) {
    if (offset == 0) {
      Get.back();
    }
    isLoadingMore.value = false;
    print(stacktrace);
    MainController mainController = Get.put(MainController());
    mainController.showErrorPopup();
  }
}