all the above are not right i will explain you how you can do it
Future<void> postPropertyAPI(BuildContext context, String projectColonyName) async {
var typeOfProperty = "";
if(widget.type == AppStrings.plots){
typeOfProperty = plotTypeProperty;
}else if(widget.type == AppStrings.commercialSpace){
typeOfProperty = commercialTypeProperty;
}else if(widget.type == AppStrings.flatHouseVilla){
typeOfProperty = flatHouseTypeProperty;
}
Loader.ProgressloadingDialog(context, true);
try {
const url = Urls.postPropertyUrl;
var formData = FormData.fromMap({
"user_id": userID,
"calony_name": projectColonyName,
"type_of_property": typeOfProperty,
// "location[0]": location,
"address": propertyAddressController.text,
"width": widthController.text,
"length": lengthController.text,
"totalarea": totalAreaController.text,
"facing": facing,
"open_side": openSide,
"transaction_type": transactionType,
"possession_status": possessionStatus,
"expected_price": expectedPriceController.text,
"price_per_square": pricePerSqFtController.text,
// "aminities": selectedAmenitiesList,
"description_details": descriptionController.text,
"buildup_area": superBuildupAreaController.text,
"floor_no": totalNoOfFloorsController.text,
"your_space_in_which_floor": floor,
"furnished_status": furnished,
"floor_no": noOfFloor,
"flat_size": flatSize,
});
formData.fields.add(MapEntry("location[]", location));
selectedAmenitiesList.forEach((amenity) {
formData.fields.add(MapEntry("aminities[]", amenity));
});
final responseDio = await Dio().post(url,data: formData,);
Loader.ProgressloadingDialog(context, false);
if (responseDio.statusCode == 200) {
print(url);
Map<String, dynamic> map = (responseDio.data as Map).cast<String, dynamic>();
PostPropertyModel response = PostPropertyModel.fromJson(map);
Utilities().toast(response.message);
if (response.status == true) {
Navigator.of(context).pop();
setState(() {});
}
}
} catch (e) {
Loader.ProgressloadingDialog(context, false);
Utilities().toast('error: $e');
}
return;
}
I want to send location and aminities in array format so dont need any changes in anywhere just do it like:
formData.fields.add(MapEntry("location[]", location));
selectedAmenitiesList.forEach((amenity) {
formData.fields.add(MapEntry("aminities[]", amenity));
});
for example selectedAmenitiesList is List<String> selectedAmenitiesList = ["one", "two", "three", "four"]
// so all are string and MapEntry() is exept only string as a socond args so one more thing you can do like
formData.fields.add(MapEntry("aminities[]", amenity.toString()));