如何禁用颤振按钮并使其变灰,直到表单完全填满,然后启用它



我一直在设计一个支付提醒应用程序,我在其中添加了多个文本字段。所以我想把下一个按钮变灰,除非所有的TextField()小部件都被正确填充。

try this:

final TextEditingController _controller1 = TextEditingController();
final TextEditingController _controller2 = TextEditingController();
final TextEditingController _controller3 = TextEditingController();
bool _isFullyEntered = false;
@override
void initState() {
super.initState();
_controller1.addListener(() {
_isFullyEntered = _checkFullyEntered();
setState((){});
});
_controller2.addListener(() {
_isFullyEntered = _checkFullyEntered();
setState((){});
});
_controller3.addListener(() {
_isFullyEntered = _checkFullyEntered();
setState((){});
});
}
bool _checkFullyEntered(String text){
if(_controller1.text == '') return false;
if(_controller2.text == '') return false;
if(_controller3.text == '') return false;

return true;
}
Button(
color: _isFullyEntered ? Colors.grey : Colors.orange,
onPressed: _isFullyEntered ? () {/*your function*/} : () {};

最新更新