Untitled

mail@pastecode.io avatar
unknown
dart
a year ago
1.3 kB
2
Indexable
Never
  Future<void> addPendingMeeting(
    String title,
    String description,
    List<File>? listOfFiles,
  ) async {
    final AuthManager authManager = Get.find();
    appTools.showLoading();

    List multiPartList = [];
    if (listOfFiles != null) {
      if (listOfFiles.isNotEmpty) {
        for (var element in listOfFiles) {
          multiPartList.add(await mpart.MultipartFile.fromFile(element.path,
              filename: element.path.split('/').last));
        }
      }
    }

    mpart.FormData form = mpart.FormData.fromMap({
      "Title": title,
      "Description": description,
      "RequestType": 1,
      "Document": multiPartList
    });

    try {
      await httpClient
          .post(getEndPointURL('PendingRequest/Add'),
              data: form,
              options: getApiOptionsWithAuth(authManager.appUser.value.token!))
          .then((response) async {
        if (response.statusCode == 200) {
          Get.back();
          appTools.showSuccessSnackBar('successMessage', timer: 1);
          print(response.data);
        }
      });
    } on DioError catch (e) {
      print(e.response);

      Get.back();
      appTools.showFailedSnackBar('errorMessage', timer: 1);
    }
  }