how i can send multiple data in Flutter. Mi data like so:
i have dynamic list with children a child have name and birthday and a list of images!
I would like to send the entire data set to the server so that it is clear which picture belongs to which child. How do I do that in Flutter?
My code:
class SaveChildren {
List children = [];
List childrenData = [];
int serviceId;
SaveChildren({this.serviceId, this.children});
Future<http.Response> saveChildren() async {
for (var i = 0; children.length > i; i++) {
childrenData.add({
'geburtsdatum': children[i].birthDay,
'name': 'leer',
'vorname': 'leer',
'nachweise': children[i].imageFiles,
});
}
var _url = "${Domains().APIDomain}/antrag/${serviceId}/uebernimmKinder";
var request = new http.MultipartRequest("PATCH", Uri.parse(_url));
request.fields['antragId'] = serviceId.toString();
request.files.add(
http.MultipartFile.fromBytes(
'kinder',
utf8.encode(json.encode(childrenData)),
contentType: MediaType(
'application',
'json',
{'charset': 'utf-8'},
),
),
);
try {
await request.send();
} catch (e) {
print(e.toString());
}
}
}