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

后端 未结 5 795
北荒
北荒 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 21:09

    Just found the answer. No. According to the onPressed property of the RaisedButton class, the onPressed property has a type of VoidCallback, which return void and according to the docs VoidCallBack is the Signature of callbacks that have no arguments and return no data.

    Edit: Thanks guys. To solve this, you use an anonymous function, like so

    (){your code here}

提交回复
热议问题