I want to post data that contains array of subjects with dio package in flutter, but I got this error:
"DioError [bad response]: The request returned an invalid status code of 500."
dio package version is 5.1.2, and I tried older versions too.
This is my post method request code:
Dio()
.post('${Urls.baseUrl}/vendor/v1/stores/updateItemByGroup',
options: Options(
headers: {
"Accept": "application/json",
"Authorization": "Bearer $token"
},
),
queryParameters: queryParameters)
This is query parameters that I pass to post method at below:
var data = {
"store_id": widget.storeId.toString(),
"for": "stock",
"same_amount": 'false'
};
for (int i = 0;i < widget.items.data!.length;i++) {
data.addAll({
"items[$i]": jsonEncode(ref
.watch(editStocksProvider.notifier)
.state[i])
});
}
I tried to send it with this model too, but it doesn't work:
class EditedStockDataModel {
String? storeId;
List<EditedStockModel>? items;
String? type;
String? sameAmount;
EditedStockDataModel( {this.type, this.sameAmount,this.storeId, this.items});
EditedStockDataModel.fromJson(Map<String, dynamic> json) {
storeId = json['store_id'];
if (json['items'] != null) {
items = <EditedStockModel>[];
json['services'].forEach((v) {
items!.add( EditedStockModel.fromJson(v));
});
}
type = json['type'];
sameAmount = json['same_amount'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['store_id'] = this.storeId;
data['items'] = this.items;
data['for'] = this.type;
data['same_amount'] = this.sameAmount;
if (this.items != null) {
data['services'] = this.items!.map((v) => v.toJson()).toList();
}
return data;
}
}
class EditedStockModel {
int? id;
String? stock;
String? maxPerOrder;
EditedStockModel({this.id, this.stock, this.maxPerOrder});
EditedStockModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
stock = json['stock'];
maxPerOrder = json['max_per_order'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['stock'] = this.stock;
data['max_per_order'] = this.maxPerOrder;
return data;
}
}
This is how request works in postman: