title: Callback function not working in flutter
body: <p>Creating an example to learn callbacks in <code>Flutter</code>. It's a simple programme to increase the counter onTap of a <code>GestureDetetor</code> But, the callback method is not working. The count increase on hot reload but not on tap. Below is the code with comments.</p>
  
  <pre><code>class BoxState extends State&lt;ChangeBoxState&gt;{
    int _counter = 0;
  
    //Callback method changes the state onTap of GestureDetector widget. It is not calling onTap.
    increaseCount(){
      setState(() {
        ++_counter;
        print(_counter);
      });
    }
  
    @override
    Widget build(BuildContext context) {
      // Passing the callback method,"increaseCount()" to stateless class where GestureDetector is defined.
      return BoxWidget(onPressed: increaseCount(), counter: _counter,);
    }
  
  }
  </code></pre>
  
  <p>Stateless class:</p>
  
  <pre><code>class BoxWidget extends StatelessWidget{
  
    BoxWidget({this.onPressed, this.counter});
  
    final VoidCallback onPressed;
    final int counter;
  
    @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return Container(
        decoration: BoxDecoration(color: Colors.blue[500]),
        child: Column(
          children: &lt;Widget&gt;[Center(child: Text('Hello, world!')),
          GestureDetector(
            onTap: onPressed, //Passing onPressed to onTap.
  
            child: Container(
              margin: const EdgeInsets.only(left:0.0, top:200.0, right:0.0, bottom:0.0),
              height: 200.0,
              width: 200.0,
              decoration: BoxDecoration(
                color: Colors.teal[200],
                border: Border.all(color: Colors.yellow, width: 10.0, style: BorderStyle.solid),
                borderRadius: BorderRadius.all(Radius.circular(20.0)),
              ),
              child: Center(child: Text(counter.toString())),
            ),
          ),
          ],
        ),
      );
    }
  }
  </code></pre>