void addToCart(ProductModel product) {
if (cartItems.contains(product)) {
int index = cartItems.indexOf(product);
cartItems.remove(product);
product.quantity = 1;*/Error on this line/*
cartItems.insert(index, product);
} else {
if (product.quantity == 0) {
product.quantity = 1;*/Error on this line/*
}
cartItems.add(product);
}
}
void decreaseQuantity(ProductModel product) {
if (cartItems.contains(product)) {
int index = cartItems.indexOf(product);
cartItems.remove(product);
if (product.quantity > 1) {
product.quantity -= 1*/Erroro on here/*;
cartItems.insert(index, product);
}
}
}
Error
The method ' ' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!').
CodePudding user response:
use
product.quantity ;
hope this helpts
CodePudding user response:
3 solutions are available to you:
Add
!
product.quantity! = 1;
Initialize the quantity by
0
in the ProductModelChange the type of the quantity by
dynamic
One of them can help