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

前端 未结 5 877
甜味超标
甜味超标 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:34

    void _incrementCounter() {
        setState(() {
            _counter++;
        });  
    }    
    
    floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    

    * As I see that in your code the return type is void for the function. in flutter if the return type is void and the function is defined in the same class, where the defined function is being called in the widget then we don't use parentheses. in a flutter, we simply call the function with using parentheses ...... which ultimately act as a pointer which will point towards function with return type void and defined in the same class in which function is called in widget *

提交回复
热议问题