如果在flutter中无法将Future函数分配给onPressed怎么办? [英] What to do If I can't assign Future functions to onPressed in flutter?
本文介绍了如果在flutter中无法将Future函数分配给onPressed怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我倾向于在将来的方法中为onpressed分配一个符号:无法将参数类型"Future"分配给参数类型"void Function()".
I have a proplem in assigning a sign in future method to onpressed :The argument type 'Future' can't be assigned to the parameter type 'void Function()'.
推荐答案
您必须像这样分配它:
onpressed: () => FunctionName()
因为处理程序期望一个没有返回值的函数.因此,我们只需在匿名void函数中调用您的函数即可.
Because the handler expects a function with no return. So we just call your function inside an anonymous void function.
这篇关于如果在flutter中无法将Future函数分配给onPressed怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文