title: How to write only one function to increment different counter variables in flutter?
body: <p>I'm trying to build a screen in flutter where,
  I have three rows in a column, each  consists of: </p>
  
  <ol>
  <li>text</li>
  <li>IconButton(add icon)</li>
  <li>text</li>
  </ol>
  
  <p>When I'm clicking on the add icon I need to increment a counter variable and display it as Text(third bullet point)</p>
  
  <p>Checkout the screenn here  : <a href="https://ibb.co/37v4rDj" rel="nofollow noreferrer">https://ibb.co/37v4rDj</a></p>
  
  <p>But I'm writing different functions for different counter variables, I don't want that, I want to write a single function which can increment different counter variables</p>
  
  <p>This is my code :</p>
  
  <pre><code> import 'package:flutter/material.dart';
  
      void main() {
        runApp(MyHomeApp());
      }
  
      class MyHomeApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          // TODO: implement build
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            home: Scaffold(
              appBar: AppBar(
                title: Text("ctr trial"),
              ),
              body: Body(),
            ),
          );
        }
      }
  
      class Body extends StatefulWidget {
        @override
        _BodyState createState() =&gt; _BodyState();
      }
  
      class _BodyState extends State&lt;Body&gt; {
  
        int upactr = 0;
        int ndactr = 0;
        int othctr = 0;
  
        @override
        Widget build(BuildContext context) {
          return Center(
            child: Column(
              //mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                SizedBox(
                  height: 100,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: &lt;Widget&gt;[
                    Text("UPA"),
                    IconButton(
                      icon: Icon(
                        Icons.add,
                      ),
                      onPressed: () { 
              setState(){
              _incrementctr;  // this function should increment only the upactr variable 
              }
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                Text("NDA"),
                IconButton(
                  icon: Icon(
                    Icons.add,
                  ),
                  onPressed: () {
              setState(){
              _incrementctr;  // this function should increment only the ndactr variable 
                  }
              },
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                Text("others"),
                IconButton(
                  icon: Icon(
                    Icons.add,
                  ),
                  onPressed: () {
              setState(){
  
              _incrementctr;  // this function should increment only the othctr variable 
              }}
  },
                ),
              ],
            ),
          ],
        ),
      );
    }
  
    void _incrementctr() {
        // this is a single function which should incerement only one counter variable , any of the following :       
      //1.upactr++;
      //2.ndactr++;
      //3.othctr++;
        }
      }
  </code></pre>