What is the difference between calling the function without parentheses and with parentheses

前端 未结 5 874
甜味超标
甜味超标 2021-01-21 08:47

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

5条回答
  •  借酒劲吻你
    2021-01-21 09:42

    Here is the difference:

    onPressed: _incrementCounter is a reference to an existing function is passed.

    This only works if the parameters of the callback expected by onPressed and _incrementCounter are compatible.

    onPressed: _incrementCounter() _incrementCounter() is executed and the returned result is passed to onPressed. This is a common mistake when done unintentionally when actually the intention was to pass a reference to _incrementCounter instead of calling it.

提交回复
热议问题