Search code examples
buttondartflutteridentify

How to identify which button is clicked in flutter


I have 4 buttons showing a different list each time a button is clicked . How to identify which button is clicked using flutter ?


Solution

  • You can assign a callback that calls a different method for each button

    new FlatButton(
      child: new Text(confirmText),
      onPressed: () => onOkPressed(),
    ),
    

    or you can pass a parameter

    new FlatButton(
      child: new Text(confirmText),
      onPressed: () => onButtonPressed('okButton'),
    ),