title: How to increase items Quantity in E-Commerce Cart using Provider in Flutter
body: <p>I want to increase the quantity of product when I click on the add button in the productview or add to cart multiple time but I do not increase its quantity remain the same, someone helps me to solve this problem. How can I give an index to the items?</p>
  <p>I am using Provider for state management</p>
  <p>ProviderSpace.dart</p>
  <pre><code>import 'dart:collection';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/foundation.dart';
  
  class AddItem extends ChangeNotifier {
    List&lt;Cart&gt; _addNewData = [];
  
  
    int get newDataCount {
      return _addNewData.length;
    }
  
    UnmodifiableListView&lt;Cart&gt; get tasks {
      return UnmodifiableListView(_addNewData);
    }
  
    void addCardManager(String itemName, String assetName, int itemRate,
        int quantity, String type) {
      final newAddItem = Cart(
        name: itemName,
        type: type,
        rate: itemRate,
        asset: assetName,
      );
      _addNewData.add(newAddItem);
      notifyListeners();
    }
  
    void updateTask(Cart task) {
      task.toggleDone();
      notifyListeners();
    }
  
    void decrease(Cart task) {
      task.decreaseDown();
      notifyListeners();
    }
  
    void removeCard(Cart task) {
      _addNewData.remove(task);
      notifyListeners();
    }
  }
  
  class Cart {
    final String name;
    final String asset;
    final String type;
    final int rate;
    int quantity;
  
    Cart({
      this.name,
      this.asset,
      this.type,
      this.rate,
      this.quantity = 1,
    });
  
    void toggleDone() {
      quantity++;
    }
  
    void decreaseDown() {
      quantity == 0 ? 0 : quantity--;
    }
  
  }
  </code></pre>
  <p>The code where I need to update the value</p>
  <pre><code>          changeButtonOnTap
                  ? Container(
                      width: 80,
                      height: 25,
                      child: FlatButton(
                        onPressed: () {
                          Provider.of&lt;AddItem&gt;(context, listen: false)
                              .addCardManager(widget.name, widget.name,
                                  widget.mrp, widget.quantity, widget.type);
                          setState(() {
                            changeButtonOnTap = false;
                          });
                        },
                        color: Color(0xffFF6200),
                        child: Text(&quot;Add&quot;,
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 11,
                              color: Color(0xffffffff),
                            )),
                      ),
                    )
                  : Container(
                      height: 25.00,
                      width: 80,
                      decoration: BoxDecoration(
                        color: Color(0xffFF6200),
                        borderRadius: BorderRadius.circular(30.00),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          GestureDetector(
                              onTap: () {                                          &lt;-----here i need to make change
                                Provider.of&lt;AddItem&gt;(context, listen: false)
                                    .updateTask(Provider.of&lt;AddItem&gt;(context,
                                            listen: false)
                                        .tasks[0]);
                                setState(() {
                                  value++;
                                  print(Provider.of&lt;AddItem&gt;(context,
                                          listen: false)
                                      .newDataCount);
                                });
                              },
                              child: Icon(Icons.add_circle,
                                  color: Colors.white)),
                          Text(
                            value.toString(),
                            style: TextStyle(color: Colors.white),
                          ),
                          GestureDetector(
                            onTap: () {
                              setState(() {
                                value &gt;= 2 ? value-- : null;
                              });
                            },
                            child: Icon(
                              Icons.do_not_disturb_on,
                              color: Colors.white,
                            ),
                          )
                        ],
                      ),
                    )
  </code></pre>