Upon research, Flutter's Button is disabled automatically when the onPressed is null. However due to my necessary testing function I am forced to place an arrow function () => , which doesn't seem to trigger the onPressed as actually null, but returning null as value. Therefore currently the button just does nothing (null) when textField is empty. I am aiming to disable it fully (grayed out) if the textField is empty.
onPressed: () => (_textController.text.isNotEmpty) ? _addNewPair() : null,
showDialog(
context: this.context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Add a custom word'),
content: _renderForm(),
actions: <Widget>[
FlatButton(
child: Text('ADD'),
onPressed: () => (_textController.text.isNotEmpty) ? _addNewPair() : null,
),
],
);
}
Put the condition first, if text is empty your button will be disabled.
onPressed: (_textController.text.isNotEmpty) ? () => _addNewPair() : null,
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