Flutter 未处理的异常:将对象转换为可编码对象失败:';Porder&x27;
我有一个purchase order类,包含一个变量和另一个名为purchase order details的类的列表,我试图将purchase order和purchase order details以对象和列表的形式从Flatter ui发送到API,但按下调用API服务的按钮时出现此错误,主要问题是如何将Porder转换为json 你知道如何解决这个问题吗,提前谢谢 代码Flutter 未处理的异常:将对象转换为可编码对象失败:';Porder&x27;,flutter,dart,Flutter,Dart,我有一个purchase order类,包含一个变量和另一个名为purchase order details的类的列表,我试图将purchase order和purchase order details以对象和列表的形式从Flatter ui发送到API,但按下调用API服务的按钮时出现此错误,主要问题是如何将Porder转换为json 你知道如何解决这个问题吗,提前谢谢 代码 class Porder { int _OrVId; List<Pdetails> _order
class Porder {
int _OrVId;
List<Pdetails> _ordersData;
Porder(this._OrVId,this._ordersData);
int get OrVId=> _OrVId;
List get ordersData=> _ordersData;
set OrVId (int newOrVId){
_OrVId = newOrVId;
}
set ordersData (List newordersData){
_ordersData = newordersData;
}
Map<String,dynamic> toMap(){
var map=Map<String,dynamic>();
map["OrVId"]=_OrVId;
map["ordersData"]=_ordersData;
return map;
}
Porder.fromObject(dynamic o){
this._OrVId=o["OrVId"];
this._ordersData=o["ordersData"];
}
}
class Pdetails {
int _OrIId;
double _OrPrice;
int _OrQ;
Pdetails(this._OrIId,this._OrPrice,this._OrQ);
int get OrIId=> _OrIId;
double get OrPrice=> _OrPrice;
int get OrQ=> _OrQ;
set OrIId (int newOrIId){
_OrIId = newOrIId;
}
set OrPrice (double newOrPrice){
_OrPrice = newOrPrice;
}
set OrQ (int newOrQ){
_OrQ = newOrQ;
}
Map<String,dynamic> toMap(){
var map=Map<String,dynamic>();
map["OrIId"]=_OrIId;
map["OrPrice"]=_OrPrice;
map["OrQ"]=_OrQ;
return map;
}
Pdetails.fromObject(dynamic o){
this._OrIId=o["OrIId"];
this._OrPrice=o["OrPrice"];
this._OrQ=o["OrQ"];
}
}
钮扣
onPressed: () async {
List<Pdetails> pdl = new List<Pdetails>();
for (var product in products) {
Pdetails pdetails = new Pdetails(product.item, product.sPrice.toDouble(), product.q);
pdl.add(pdetails);
}
sOrder = apiServices();
porder = Porder(globals.vendorid,pdl);
final saveResponse =
await sOrder.saveOrderData(porder);
// showCustomDialog(products, context);
},```
onPressed:()异步{
List pdl=新列表();
用于(产品中的var产品){
Pdetails Pdetails=新的Pdetails(product.item,product.sPrice.toDouble(),product.q);
pdl.add(PDE详细信息);
}
sOrder=apiServices();
porder=porder(全球供应商,pdl);
最终保存响应=
wait sOrder.saveOrderData(porder);
//showCustomDialog(产品、上下文);
},```
我想你会问(你怎么能很好地使用toMap!?)所以使用toMap,即返回{'first':_OvId,'second':_AnyThing}。。像这样试试
onPressed: () async {
List<Pdetails> pdl = new List<Pdetails>();
for (var product in products) {
Pdetails pdetails = new Pdetails(product.item, product.sPrice.toDouble(), product.q);
pdl.add(pdetails);
}
sOrder = apiServices();
porder = Porder(globals.vendorid,pdl);
final saveResponse =
await sOrder.saveOrderData(porder);
// showCustomDialog(products, context);
},```