title: How to reference the value of a form field in the validator or another form field in flutter
body: <p>In the code below, I am trying to test the value of the repeat password against the saved value of the new password field. This value is saved to the variable _newPW. But in the repeat passwords text form field, the _newPW variable is always blank.</p>
  
  <p>How should I do this? I just want to validate that the two new passwords match. Thanks.</p>
  
  <pre><code>          TextFormField(
              obscureText: true,
              validator: (value) {
                if (value.isEmpty) {
                  return 'please enter the new password';
                }
                return null;
              },
              onSaved: (value) {
                _newPW = value;
              },
              decoration: _textFormFieldDecoration(
                hintText: 'new password',
                padding: 8.0,
              ),
            ),
  
            TextFormField(
              obscureText: true,
              validator: (value) {
                if (value.isEmpty) {
                  return 'please enter the new password';
                } else if (value != _newPW) {
                  print('value = $value');
                  print('newPW = $_newPW');           // &lt;-- _newPW variable is blank
                  return 'new passwords must match';
                }
                return null;
              },
              decoration: _textFormFieldDecoration(
                hintText: 'repeat new password',
                padding: 8.0,
              ),
            ),
  </code></pre>