toFormData method
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 (rate != null) {
data["rate"] = rate!;
}
if (comment != null) {
data["comment"] = comment!;
}
if (photos != null) {
data["photos"] = await Future.wait(photos!.map((e) async {
return await MultipartFile.fromFile(e.path);
}));
}
return FormData.fromMap(data);
}