List<Product> myProducts = [];
I have made a list builder so that with every product clicked it is added to the list
myProducts.add(Product(
id: product.id,
name: product.name,
price: product.price));
how do i add the price of all the values in the list?
I wasnt sure what to do so I tried researching
myProducts.reduce((value, element) => element.price + value.price)
is this the way to do it?
I hope to get the sum of all the values in my list
>Solution :
double totalPrice = myProducts.fold(0, (sum, product) => sum + product.price);