generateMultipart method

Future<Uint8List> generateMultipart(
  1. EncodeBarcodeType barcodeType,
  2. String data, {
  3. EncodeDataType? dataType,
  4. BarcodeImageFormat? imageFormat,
  5. CodeLocation? textLocation,
  6. String? foregroundColor,
  7. String? backgroundColor,
  8. GraphicsUnit? units,
  9. double? resolution,
  10. double? imageHeight,
  11. double? imageWidth,
  12. int? rotationAngle,
})

Generate barcode using POST request with parameters in multipart form.

Implementation

Future<Uint8List> generateMultipart(
    EncodeBarcodeType barcodeType, String data,
    {EncodeDataType? dataType,
    BarcodeImageFormat? imageFormat,
    CodeLocation? textLocation,
    String? foregroundColor,
    String? backgroundColor,
    GraphicsUnit? units,
    double? resolution,
    double? imageHeight,
    double? imageWidth,
    int? rotationAngle}) async {
  // ignore: prefer_final_locals
  Object? postBody;

  // create path and map variables
  final String requestPath = "/barcode/generate-multipart";

  // query params
  final List<QueryParam> queryParams = [];
  final Map<String, String> headerParams = {};
  final Map<String, String> formParams = {};

  final List<String> contentTypes = ["multipart/form-data"];

  final String contentType =
      contentTypes.isNotEmpty ? contentTypes[0] : "application/json";
  final List<String> authNames = ["JWT"];

  MultipartRequestPlus mp =
      MultipartRequestPlus('POST', Uri.parse(requestPath));

  mp.fields['barcodeType'] = [parameterToString(barcodeType)];

  if (dataType != null) {
    mp.fields['dataType'] = [parameterToString(dataType)];
  }

  mp.fields['data'] = [parameterToString(data)];

  if (imageFormat != null) {
    mp.fields['imageFormat'] = [parameterToString(imageFormat)];
  }

  if (textLocation != null) {
    mp.fields['textLocation'] = [parameterToString(textLocation)];
  }

  if (foregroundColor != null) {
    mp.fields['foregroundColor'] = [parameterToString(foregroundColor)];
  }

  if (backgroundColor != null) {
    mp.fields['backgroundColor'] = [parameterToString(backgroundColor)];
  }

  if (units != null) {
    mp.fields['units'] = [parameterToString(units)];
  }

  if (resolution != null) {
    mp.fields['resolution'] = [parameterToString(resolution)];
  }

  if (imageHeight != null) {
    mp.fields['imageHeight'] = [parameterToString(imageHeight)];
  }

  if (imageWidth != null) {
    mp.fields['imageWidth'] = [parameterToString(imageWidth)];
  }

  if (rotationAngle != null) {
    mp.fields['rotationAngle'] = [parameterToString(rotationAngle)];
  }

  postBody = mp;

  final response = await _apiClient.invokeAPI(
      requestPath,
      'POST',
      queryParams,
      postBody,
      headerParams,
      formParams,
      contentType,
      authNames);

  if (response.statusCode >= 400) {
    ApiErrorResponse error;
    try {
      error = _apiClient.deserialize(response.body, 'ApiErrorResponse');
    } catch (e) {
      throw ApiException(response.statusCode, response.body);
    }
    throw ApiException.withResponse(
        response.statusCode,
        response.reasonPhrase == null
            ? "Api response error"
            : response.reasonPhrase!,
        error);
  } else {
    return response.bodyBytes;
  }
}