Flutter onHover:(something)=>;功能(上下文)和悬停:颤振中的功能(上下文)?

Flutter onHover:(something)=>;功能(上下文)和悬停:颤振中的功能(上下文)?,flutter,Flutter,当我执行onHover:function(context)时,它会给我错误信息 但是onHover:(事件)=>函数(上下文)工作正常 有什么区别? onHover是否应该始终有一个变量(PointerHoverEvent) 可能返回参数不想要的东西,onHover参数想要一个函数,在这里onHover:(事件)=>函数(上下文)您给它的是参数想要的函数 给你一个主意 //this is a function Function functionWhichReturnsInt = (){retu

当我执行
onHover:function(context)
时,它会给我错误信息

但是
onHover:(事件)=>函数(上下文)
工作正常

有什么区别? onHover是否应该始终有一个变量(PointerHoverEvent)

可能返回参数不想要的东西,
onHover
参数想要一个函数,在这里
onHover:(事件)=>函数(上下文)
您给它的是参数想要的函数

给你一个主意


//this is a function
Function functionWhichReturnsInt = (){return 1;};

//this is function which needs function
void feedMeAFunction(Function food){
  food();
}

//this is a function which needs int
void feedMeAnInt(int food){
  print(food);
}

//we can call the functions like this
//passing a function
feedMeAFunction(functionWhichReturnsInt);
//passing an int
feedMeAnInt(functionWhichReturnsInt());
可能返回参数不想要的东西,
onHover
参数想要一个函数,在这里
onHover:(事件)=>函数(上下文)
您给它的是参数想要的函数

给你一个主意


//this is a function
Function functionWhichReturnsInt = (){return 1;};

//this is function which needs function
void feedMeAFunction(Function food){
  food();
}

//this is a function which needs int
void feedMeAnInt(int food){
  print(food);
}

//we can call the functions like this
//passing a function
feedMeAFunction(functionWhichReturnsInt);
//passing an int
feedMeAnInt(functionWhichReturnsInt());

是的,总是需要一个函数来完成事件。如果您没有使用事件,只需执行()=>function(context)是的,它始终需要是接收事件的函数。如果不使用事件,只需执行()=>函数(上下文)