How to properly enable/disable Flutter's Button

Question

Asked by Jesse on December 11, 2018 (source).

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,
        ),
      ],
    );
  }

Answer

Question answered by diegoveloper (source).

Put the condition first, if text is empty your button will be disabled.

onPressed: (_textController.text.isNotEmpty) ? () =>  _addNewPair() : null,
DART FLUTTER
SHARE: