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 {
  Map<String, dynamic> data = <String, dynamic>{};
  if (email != null) {
    data["email"] = email!;
  }
  if (password != null) {
    data["password"] = password!;
  }
  if (name != null) {
    data["name"] = name!;
  }
  if (surname != null) {
    data["surname"] = surname!;
  }
  if (phoneNumber != null) {
    data["phoneNumber"] = phoneNumber!;
  }
  if (birthday != null) {
    data["birthday"] = birthday!;
  }
  if (gender != null) {
    data["gender"] = gender!.toString().split('.').last;
  }
  if (companyName != null) {
    data["companyName"] = companyName!;
  }
  if (taxOffice != null) {
    data["taxOffice"] = taxOffice!;
  }
  if (taxNumber != null) {
    data["taxNumber"] = taxNumber!;
  }
  if (photo != null) {
    data["photo"] = await MultipartFile.fromFile(photo!.path);
  }
  return FormData.fromMap(data);
}