Here I am trying to send the Object Map in the multipart request but my request is going as a string, i need send the Object Map not String . but request .fields wants a String from me.
"barberAddress":{
"State":"test",
"City":"test",
"Street": "test",
"location":{
"lat":1.2,
"lang":2.1
}
},
This is my post method
postFormDataBarber({
@required String endPoint,
File picB,barberName,BarberAddress barberAddress, }) async {
var url = Uri.parse('${BaseUrl.baseUrl}$endPoint');
var request = http.MultipartRequest("POST", url);
request.fields["barberAddress"] = json.encode(barberAddress);// {"State":"aaa","City":"vvv","Street":"eeee","location":{"lat":null,"lang":null}}
request.files.add(picB);
final data = await request.send();
return data;
}
This is my model and I want to add this model map object to the Mango database
class BarberAddress {
BarberAddress({
@required this.state,
@required this.city,
@required this.street,
this.location,
});
String state;
String city;
String street;
BarberLocation location;
factory BarberAddress.fromJson(Map<String, dynamic> json) =>
BarberAddress(
state: json["State"],
city: json["City"],
street: json["Street"],
location: BarberLocation.fromJson(json["location"]),
);
class BarberLocation {
BarberLocation({
@required this.lat,
@required this.lang,
});
double lat;
double lang;
factory BarberLocation.fromJson(Map<String, dynamic> json) =>
BarberLocation(
lat: json["lat"].toDouble(),
lang: json["lang"].toDouble(),
);
Map<String, dynamic> toJson() => {
"lat": lat,
"lang": lang,
};
}