我试图做一个注册页面,除了onpressed属性的逻辑外,其他所有东西都在工作。这是我的代码:
onPressed: _usernameController.text == "" || _emailController.text == "" || _passwordController.text == "" || _passController.text == "" ? null : () {
setState(() {
_isLoading = true;
});
register(_usernameController.text, _emailController.text, _passwordController.text, _passController.text);
}
即使您填写所有必填字段,就像条件保持为真一样,按钮也保持为空。我知道代码是正确的,因为我的登录页面中有类似的逻辑,而且每当刷新字段已满的内容时,它都会神奇地点亮按钮,一切正常。可能是什么问题?
答案 0 :(得分:0)
您可以使用Form小部件。表单小部件具有onChange属性,您还可以侦听所有状态。表单小部件具有其他属性,密钥已验证并控制您的表单状态。不要忘记必须声明验证器属性。
完整代码:Form Validattor
答案 1 :(得分:0)
请采用以下一种方法。.
void _registration(){
//add register code here instead of write at onPressed event
}
并像这样在onPressed事件中调用此方法...
onPressed: _registration