我有一个简单的表单,带有一个用于计算表单的按钮。我认为最好点击按钮开始计算操作并将变量传递给哑函数,而不是让函数知道它不需要知道的文本字段。我可以这样做吗?或者我的计算函数是否需要访问我的文本字段?
new Container(
color: Colors.grey.shade300,
padding: new EdgeInsets.all(15.0),
child: new Column(
children: <Widget>[
new TextField(
controller: _ageController,
decoration: new InputDecoration(
icon: new Icon(Icons.person_outline), labelText: "Age"),
),
new TextField(
controller: _heightController,
decoration: new InputDecoration(
icon: new Icon(Icons.insert_chart),
labelText: "Height (in feet)"),
),
new TextField(
controller: _weightController,
decoration: new InputDecoration(
icon: new Icon(Icons.line_weight),
labelText: "Weight (in lbs)"),
),
new Padding(padding: new EdgeInsets.only(top: 20.0)),
new RaisedButton(
onPressed: calculate(1, 2),
color: Colors.pinkAccent,
child: new Text(
"Calculate",
style: new TextStyle(color: Colors.white),
),
)
],
),
),
],
),
);
}
void calculate(num1, num2) {
}
}