Can't get button press to work in flutter

后端 未结 4 1037
再見小時候
再見小時候 2021-01-18 06:54

Ok I\'m pretty new to flutter/ dart so go easy on me. I\'m just trying to make a very simple app where when you press a button some text updates telling you how many times

4条回答
  •  独厮守ぢ
    2021-01-18 07:15

    Your problem is that you didn't pass a callback to RaisedButton, you invoked your callback.

    new RaisedButton(
      onPressed: _buttonWasPressed(), // invokes function
      child: new Row(children: [new Text("Press meh")]),
    );
    

    To pass a callback to another widget you have two choices:

    Pass a tear-off

     new RaisedButton(
       onPressed: _buttonWasPressed, // no `()`,
       child: ...
     )
    

    Pass a closure

     new RaisedButton(
       onPressed: () {
         // do something.
       },
       ..
     )
    

提交回复
热议问题