saveReimbursementStatus method

dynamic saveReimbursementStatus({
  1. dynamic packageId,
  2. dynamic reimbursent_Type,
  3. dynamic reimbursement_Amount,
  4. dynamic member_Id,
  5. dynamic name,
  6. dynamic relation,
  7. dynamic date_Birth,
  8. dynamic gender,
  9. dynamic context,
})

Implementation

saveReimbursementStatus({
  packageId,
  reimbursent_Type,
  reimbursement_Amount,
  member_Id,
  name,
  relation,
  date_Birth,
  gender,
  context,
}) async {
  var decodedResponse;
  try {
    var request = http.MultipartRequest(
      'POST',
      Uri.parse('${medicine_API}api/save-reimbursement-details'),
    );

    request.headers.addAll({"Authorization": currentUserToken});
    request.fields['package_id'] = '$packageId';
    request.fields['reimbursement_type'] = '$reimbursent_Type';
    request.fields['reimbursement_amount'] = '$reimbursement_Amount';
    request.fields['member_id'] = '';
    request.fields['name'] = '$name';
    request.fields['relation'] = '$relation';
    request.fields['date_of_birth'] = '$date_Birth';
    request.fields['gender'] = '$gender';

    if (uploadedDocuments.isNotEmpty) {
      for (int i = 0; i < uploadedDocuments.length; i++) {
        request.fields['document_type[$i]'] =
            await '${uploadedDocuments[i]['file_type']}';
        request.files.add(await http.MultipartFile.fromPath(
          "document[$i]",
          uploadedDocuments[i]['file_path'].toString(),
        ));
      }
    }

    var response = await request.send();
    var responsed = await http.Response.fromStream(response);
    decodedResponse = json.decode(responsed.body);
    print(responsed.body);
    Get.back();
    if (decodedResponse['success'] == true) {
      Get.back();
      Get.offAll(MyProfileScreen());
      Get.to(ReimbursementStatus());
      await showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return PinCodePopUp(
            messag: "${decodedResponse['message']}",
            image: '${LottiePath}Upload_Successful.json',
          );
        },
      );
    } else {
      Get.back();
      Validator().errorMessage(
        context: context,
        message: decodedResponse['message'] ?? "Something went wrong",
      );
    }
  } catch (e) {
    Validator().errorMessage(
      context: context,
      message: "${decodedResponse['message']}",
    );
  }
}