callproductDetailsApi method

Future<void> callproductDetailsApi(
  1. List<Partner> partner,
  2. ScanModel scanModel
)

Implementation

Future<void> callproductDetailsApi(
    List<Partner> partner, ScanModel scanModel) async {
  if (kDebugMode) {
    print(partner);
  }
  BuildContext context = Get.context!;
  WidgetsBinding.instance.addPostFrameCallback((_) {
    Helper.progressDialog(context, "Please wait..");
  });
  for (var element in partner) {
    partnerIds.add(element.partnerId!);
  }
  dio
      .get(
    'https://run.mocky.io/v3/12f04fd8-f7d0-4b34-b71e-9f21f91cf580',
    data: {
      'partnerIds': partnerIds,
    },
    options: Options(
      headers: {
        'Authorization': 'Bearer Authorization',
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    ),
  )
      .then((response) {
    Get.back();
    if (response.data != null) {
      ProductdataModel model = ProductdataModel();
      if (kDebugMode) {
        print(response.data);
      }
      Map<String, dynamic> productData = response.data;
      if (productData['status']) {
        DataproductModel dataproductModel =
            DataproductModel.fromJson(productData['data']);
        productDataList.value = dataproductModel.content!;
        productDataScannedList.value = productDataList;
        searchedScannedList.value = productDataList;
        Get.to(() => Scan(model: scanModel));
      } else {
        model.errors = productData["errors"];
        if (productData["errors"] != null) {
          Helper.messageDialog(
              Get.context!,
              model.errors![0].errorCode ?? "Try again!!",
              model.errors![0].errorDescription ?? "Something went wrong");
        }
      }
    }
  }, onError: (error) {
    if (kDebugMode) {
      print(error.toString());
    }
    Get.back();
    Helper.messageDialog(Get.context!, "Try Again!!", error.toString());
  });
}