title: How to do incrementing and decrementing of a particular product in flutter
body: <p>I'm working on a food delivery app I've tried to make an increment decrement system of a particular product in a list. At the start it works <code>i.e the counter increases</code> but a bit after the counter automatically return to <code>0</code> without any button press. I don't know why it's happening</p>
  <p><strong>Below is the code I'm trying</strong></p>
  <p>This is the class</p>
  <pre><code>class ItemData {
    final String itemName;
    final String itemPrice;
    final String image;
    int counter = 0;
    bool isAdded = false;
    ItemData({this.itemName, this.itemPrice, this.image});
  }
  </code></pre>
  <p>This is the function for getting data from url</p>
  <pre><code>  Future&lt;List&lt;ItemData&gt;&gt; _getProducts() async {
      var data = await http
          .get(&quot;https://orangecitycafe.in/app_configs/products_display.php&quot;);
  
      var jsonData = json.decode(data.body);
      List&lt;ItemData&gt; details = [];
      for (var p in jsonData) {
        ItemData detail = ItemData(
            itemName: p[&quot;product_name&quot;],
            itemPrice: p[&quot;product_price&quot;],
            image: p[&quot;product_image&quot;]);
        details.add(detail);
      }
      return details;
    }
  </code></pre>
  <p>This is the code for fetched products inside future builder</p>
  <pre><code>  Widget _myCart() {
      return FutureBuilder(
        future: _getProfile(),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (BuildContext context, int index) {
                return ListTile(
                  title: Text(snapshot.data[index].itemName),
                  leading: Image.network(&quot;https://www.orangecitycafe.in/&quot; +
                      snapshot.data[index].image),
                  trailing: snapshot.data[index].isAdded
                      ? Row(
                          mainAxisSize: MainAxisSize.min,
                          children: &lt;Widget&gt;[
                            IconButton(
                              icon: Icon(Icons.remove),
                              onPressed: () {
                                setState(() {
                                  if (snapshot.data[index].counter &gt; 0) {
                                    snapshot.data[index].counter--;
                                  }
                                });
                              },
                              color: Colors.green,
                            ),
                            Text(snapshot.data[index].counter.toString()),
                            IconButton(
                              icon: Icon(Icons.add),
                              color: Colors.green,
                              onPressed: () {
                                setState(() {
                                  snapshot.data[index].counter++;
                                });
                              },
                            ),
                          ],
                        )
                      : RaisedButton(
                        onPressed: (){
                          setState(() {
                            snapshot.data[index].isAdded = true;
                          });
                        },
                        child: Text(&quot;Add&quot;),
                      ),
                );
              },
            );
          } else {
            return Container();
          }
        },
      );
    }
  </code></pre>
  <p>The rest is working but only when I increase the counter it increases and after sometime it automatically returns to <code>0</code></p>