title: Dart: How to reduce a list of classes
body: <p>I want to reduce a list of classes for example:</p>
  
  <pre><code>class Product {
    final String name;
    final double price;
  
    Product({this.name, this.price});
  }
  
  List&lt;Product&gt; products = [
    Product(name: 'prod1', price: 100.0),
    Product(name: 'prod2', price: 300.0),
  ];
  
  void main() {
    var sum = products.reduce((curr, next) =&gt; curr.price + next.price);
    print(sum);
  }
  </code></pre>
  
  <p>but it throws an error</p>
  
  <p>Error: A value of type 'double' can't be assigned to a variable of type 'Product'.</p>