颤振错误:类 '_InternalLinkedHashMap<String, dynamic>' 没有实例方法"toMap"。接收器: _LinkedHashMap 镜头:9 尝试调用



当我尝试从管理仪表板更新订单状态时,发生了这个错误,尽管add函数成功发送到firebase,这是我的订单模型,我这样做,因为当我从firebase获得订单时,发生了错误,告诉我列表不是列表的子类型,我将list类型的购物车列表发送给listcarditemlist,并使函数添加&Get成功但是update函数出错了我不知道为什么不知道add和update有什么不同我把静态列表发送给两个函数除了状态

什么都没变
class NewOrderModel
{
String? orderId;
String? userName;
double? totalPrice;
double? shipping;
double? total;
String? phone;
String? address;
String? dateTime;
String? productName;
String? status;
int? quantity;
List<dynamic>? cardItemList;
NewOrderModel({
this.orderId,
this.userName,
this.totalPrice,
this.shipping,
this.total,
this.address,
this.phone,
this.dateTime,
this.cardItemList,
this.quantity,
this.productName,
this.status,
});
NewOrderModel.fromJson(Map<String, dynamic>? json)
{
orderId = json!['orderId'];
userName = json['userName'];
totalPrice = json['totalPrice'];
shipping = json['shipping'];
total = json['total'];
phone=json['phone'];
address=json['address'];
dateTime=json['dateTime'];
cardItemList=json['cardItemList'];
quantity=json['quantity'];
productName=json['productName'];
status=json['status'];
}
Map<String, dynamic> toMap()
{
return {
'orderId':orderId,
'userName': userName,
'totalPrice': totalPrice,
'shipping': shipping,
'total': total,
'phone': phone,
'address': address,
'dateTime': dateTime,
'status': status,
'productName': productName,
'quantity': quantity,
'cardItemList' : cardItemList?.map((e) => e.toMap()).toList()
};
}
}

,这是更新函数

void updateStatusOfOrdres(String id,{
required String status,
int? quantity,
String? productName,
String? dateTime,
String? phone,
String? address,
String? orderId,
String? userName,
double? totalPrice,
double? total,
double? shipping,
List<dynamic>? cardItemList,
})
{
NewOrderModel model = NewOrderModel(
status: status,
quantity: quantity,
productName:productName,
dateTime: dateTime,
address:address ,
orderId: orderId,
phone:phone ,
shipping:shipping ,
total: total,
totalPrice: totalPrice,
userName:userName,
cardItemList:cardItemList ,
);
FirebaseFirestore.instance
.collection('orders')
.doc(id)
.update(model.toMap())
.then((value) {
getOrders();
}).catchError((error){
emit(UpdateOrdersErrorState(error.toString()));
print(error.toString());
});
}

这是调用函数到可重用组件的方式,我发送一个NewOrderModel的列表,就像索引的newOrder一样,我让这个可重用组件,因为我为三个状态(新,确认,取消)划分订单,每个状态有一个屏幕和它的列表

AdminCubit.get(context).updateStatusOfOrdres(
AdminCubit.get(context).ordersNewId[index],
status: 'canceled',
userName:model.userName ,
totalPrice: model.totalPrice,
total:model.total ,
shipping:model.shipping ,
phone: model.phone,
orderId: model.orderId,
cardItemList: model.cardItemList,
address: model.address,
dateTime:model.dateTime,
productName: model.productName,
quantity: model.quantity,
);

谢谢你的帮助

我用这种方法终于解决了这个问题

void updateStatusOfOrdres(String id,{
required String status,
int? quantity,
String? productName,
String? dateTime,
String? phone,
String? address,
String? orderId,
String? orderNumber,
String? userName,
double? totalPrice,
double? total,
double? shipping,
String? userEmail,
List<dynamic>? cardItemList,
})
{
FirebaseFirestore.instance
.collection('orders')
.doc(id)
.update({
'orderId':orderId,
'userName': userName,
'totalPrice': totalPrice,
'shipping': shipping,
'total': total,
'phone': phone,
'address': address,
'dateTime': dateTime,
'status': status,
'productName': productName,
'quantity': quantity,
'userEmail': userEmail,
'orderNumber': orderNumber,
'cardItemList' : cardItemList?.toList(),
})
.then((value) {
getOrders();
}).catchError((error){
emit(UpdateOrdersErrorState(error.toString()));
print(error.toString());
});
}

最新更新