【发布时间】:2018-12-11 02:49:07
【问题描述】:
经研究,当 onPressed 为 null 时,Flutter 的 Button 会自动禁用。但是,由于我需要的测试功能,我不得不放置一个箭头函数 () => ,这似乎不会触发 onPressed 实际上为 null,而是将 null 作为值返回。因此,当 textField 为空时,当前按钮什么都不做(null)。如果 textField 为空,我的目标是完全禁用它(灰色)。
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,
),
],
);
}
【问题讨论】: