toFormData method

  1. @override
Future<FormData?>? toFormData()
override

Converts the body data model to a FormData object.

This method should be implemented by subclasses to convert their specific data to a FormData object. It is designed to be used with requests that need to send data as FormData, such as file uploads.

Implementation

@override
Future<FormData?>? toFormData() async {
  FormData formData = FormData.fromMap({
    'storeId': storeId,
    'message': message,
    'status': status,
    'files': files != null
        ? await Future.wait(files!
            .map((file) async => MultipartFile.fromBytes(
                file.readAsBytesSync(),
                filename: file.path.split('/').last))
            .toList())
        : null,
  });

  return formData;
}