Flutter: Can I pass arguments to a function defined in an onPress event on a button?

后端 未结 5 810
北荒
北荒 2021-02-18 20:04

I have a simple form with a button to calculate the form. I figure it\'s better to hit the button to start the action of calculating and pass the variables to the dumb function

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-18 20:45

    Shorthand function designed in such a way that it is allowed to return function with type void as mentioned in this article --> So why is returning everything allowed through a shorthand function[()=>] even if the return type is void?

    So that you have two approaches in your disposal:

    use

    onPressed: () => calculate(1, 2),
    

    or

    onPressed: (){calculate(1, 2);},
    

提交回复
热议问题