Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to auto click button in flutter?

Tags:

flutter

dart

does anyone know is there any way to click the button automatically in flutter? In javascript I use

document.getElementById('someId').click();                                                       
like image 715
TABASCO Avatar asked Oct 30 '19 04:10

TABASCO


People also ask

How do I create a dynamic button in Flutter?

First, we will create a stateful widget which will look something like this. Now, add Scaffold in our widget method of the stateful widget which will be returning the empty container and floating action button which is going to add the text fields on the press of this button.


1 Answers

If the button is in a variable, you could do something like this:

FlatButton button = FlatButton(
  child: Text("Button"),
  onPressed: () => print('pressed'),
);
button.onPressed();

If you don't know if onPressed isn't null, you could do this:

button.onPressed?.call(); // if (button.onPressed != null) button.onPressed();

Or you could do what others suggested, use the same function assigned to onPressed, like this:

FlatButton button = FlatButton(
  child: Text("Button"),
  onPressed: _myOnPressed,
);
_myOnPressed();
like image 160
Pablo Barrera Avatar answered Oct 23 '22 04:10

Pablo Barrera