does anyone know is there any way to click the button automatically in flutter? In javascript I use
document.getElementById('someId').click();
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With