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

后端 未结 5 811
北荒
北荒 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

    e.g.

        int  result = 0;
    
        void calculate(num1, num2) {
         setState(() {
             result = num1 + num2;
         });
        }
    
    
        new RaisedButton(
              onPressed: () => calculate(1, 100),
              ...
        ),
        new Text("$result")
    

提交回复
热议问题