void moveToReg()
{
//it is a function
}
onPressed: moveToReg //It works
onPressed: moveToReg(); //It gives an error
I am an absolute beginner and I want to ask why onPressed takes function without Parentheses ?
最佳答案
不带括号的onPressed take函数将引用(指针)传递给该函数moveToreg
到onPressed
参数,只是因为onPressed
和moveToreg
期望的回调参数兼容。
关于flutter - 背后的逻辑是什么,什么onPressed带入Flutter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59152538/