What is the difference between calling the function without parentheses and with parentheses on onPressed or Ontap?
I just know that void function can\'t be called with
incrementCounter is a reference to the function. You're passing the function along as a parameter to be invoked somewhere later. This is usually used as callback function, if you have a child widget
incrementCounter() will invoke the function call. For this case, your counter will automatically add 1 when the widget builds, which you don't want to happen.
And usually it is not right to call the function directly, you should write it like this:
onPressed: () {
_incrementCounter();
},
OR
onPressed: () => _incrementCounter();