我有 2 个表单域,我想验证第二个表单域以匹配第一个表单域的密码,我尝试了但没有成功..感谢您的回答。
更新:我已经有提交按钮及其工作,我希望第二个字段中的验证器验证第一个字段文本以匹配第二个字段。
new TextFormField(
controller: _registerPassController,
decoration: new InputDecoration(labelText: 'Password'),
obscureText: true,
validator: (value) =>
value.isEmpty ? 'Password can\'t be empty' : null,
onSaved: (value) => _password = value,
),
],
),
new Stack(
alignment: const Alignment(1.0, 1.0),
children: <Widget>[
new TextFormField(
controller: _registerPassController2,
decoration: new InputDecoration(labelText: 'Retype Password'),
obscureText: true,
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
},),
最佳答案
我终于找到答案了,其实很简单。
new TextFormField(
controller: _registerPassController2,
decoration: new InputDecoration(labelText: 'Retype Password'),
obscureText: true,
validator: (value) {
if (value != _registerPassController.text) {
return 'Password is not matching';
}
},
),
https://stackoverflow.com/questions/50155348/