doPostMultipart method

void doPostMultipart(
  1. OnInterfaceCallbackListener listener,
  2. Map<String, dynamic> passParaMap,
  3. List<File> fileList,
  4. String filesKeyName,
  5. String? apiName,
  6. String? apiNamePageRef,
)

Implementation

void doPostMultipart(OnInterfaceCallbackListener listener, Map<String, dynamic> passParaMap,
    List<File> fileList, String filesKeyName, String? apiName, String? apiNamePageRef) async {

  final formDataMap = <String, dynamic>{...passParaMap};

  for (var file in fileList) {
    formDataMap[filesKeyName] = await MultipartFile.fromFile(
      file.path,
      filename: file.path.split('/').last,
    );
  }

  final formData = FormData.fromMap(formDataMap);

  try {
    final response = await dio.post(
      apiName ?? '',
      data: formData,
    );

    listener.onFetchProgress(response.statusCode ?? 200, response.data, apiNamePageRef);
    listener.onFetchComplete(response.statusCode ?? 200, 'API_RESPONSE', apiNamePageRef);
  } on DioException {
    listener.onFetchComplete(700, 'ERROR', apiNamePageRef);
  } catch (e) {
    listener.onFetchComplete(700, 'ERROR', apiNamePageRef);
  }
}