【发布时间】:2019-06-14 22:20:16
【问题描述】:
我正在做一个基本的应用程序,但它不能正常工作。我有一个 TextField 但我不希望它是空的。我有一个 textController 并且我使用 errorText 但它不能正常工作。 小米代码是:
void changeDesc() { showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('New description'),
content: TextField(
controller: _textController,
decoration: InputDecoration(
hintText: "description",
errorText: descriptionIncorrect
? 'Description cannot be empty'
: null,
),
),
actions: <Widget>[
FlatButton(
child: new Text('Ok'),
onPressed: () {
setState(() {_textController.text.length == 0
? descriptionIncorrect= true
: descriptionIncorrect= false;});
if (_textController.text.length != 0) {
alert.description = _textController.text;
Navigator.of(context).pop();
}
},
),
FlatButton(
child: new Text('Cancel'),
onPressed: () {
setState(() {
_textController.text.length == 0
? descriptionIncorrect= true
: descriptionIncorrect= false;});
if (_textController.text.length == 0) {
_textController.text = alert.description;
Navigator.of(context).pop();
}
},
)
],
);
});}
当我按下 OK 按钮并且 textField 为空时,应该会出现错误,但不会出现。我已经尝试了一些东西,但我无法按照我的需要进行操作。
谢谢。
【问题讨论】: