dart - 如何根据另一个值验证表单字段?

我有 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/

相关文章:

android - Flutter 的 Multidex 问题

json - 在 Dart 中解析具有嵌套对象数组的 JSON?

dart - 如何在 Flutter 中设置 AlertDialog Actions 的样式

dart - flutter 实现粘性标题和对齐项目效果

ios - 文本字段在 iOS 模拟器上不显示键盘

visual-studio-code - 用于 flutter 的 VSCode 热重载

swift - 如何在 Flutter 中启用对现有项目的 Swift 支持

dart - Flutter 从 Firebase 存储加载图像

android - 在 Flutter 上捕获 Android 后退按钮事件

flutter - Flutter 中的 MyApp 类错误未定义方法 'setState'