参数类型' productModel?'可以将参数类型分配给ProductModel'
我正在制作一个Midel,以将产品图像,价格和名称上传到Firebase,然后我遇到此错误(参数类型'ProductModel?'无法分配到参数类型'ProductModel'。)。
class ProductProvider with ChangeNotifier {
List<ProductModel> pizzaProductList = [];
ProductModel? productModel;
fatchPizzaproductData() async {
// List<ProductModel> newList = [];
QuerySnapshot value =
await FirebaseFirestore.instance.collection("PizzaProducts").get();
pizzaProductList = value.docs.map((element) {
return ProductModel(
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
}).toList();
}
get getPizzaproductDataList {
return pizzaProductList;
}
}
I'm making a midel to upload product image,price and name to firebase then i face this error (The argument type 'ProductModel?' can't be assigned to the parameter type 'ProductModel'.)
class ProductProvider with ChangeNotifier {
List<ProductModel> pizzaProductList = [];
ProductModel? productModel;
fatchPizzaproductData() async {
// List<ProductModel> newList = [];
QuerySnapshot value =
await FirebaseFirestore.instance.collection("PizzaProducts").get();
pizzaProductList = value.docs.map((element) {
return ProductModel(
productImage: element.get("productImage"),
productName: element.get("productName"),
productPrice: element.get("productPrice"),
);
}).toList();
}
get getPizzaproductDataList {
return pizzaProductList;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
productModel
是一种不可用的类型,而pizzaproduct
是不可删除的productmodel
s的列表。而不是在类上存储属性
productModel
,而是考虑从value.docs
pizzaproduct
直接映射,并删除存储模型的中间步骤在productModel
中:The problem is that
productModel
is a nullable type, whereaspizzaProduct
is a List of non-nullableProductModel
s.Instead of storing a property
productModel
on your class, consider mapping directly fromvalue.docs
topizzaProduct
, and removing the intermediate step of storing the model inproductModel
: